Hello, I have made several optimizations in loading script-fu extension making the loading process a bit faster. It's the first time I change something in an open source program and don't know best way to "announce" it and get it reviewed, so I send a patch in a mail. The major speedup is caused by calling my function load_script_file instead of script_fu_run_command("(load ...."). Please review my changes and send an answer if the patch is OK.
diff -rup /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/scheme-wrapper.c gimp/plug-ins/script-fu/scheme-wrapper.c --- /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/scheme-wrapper.c 2010-08-24 17:49:15.000000000 +0200 +++ gimp/plug-ins/script-fu/scheme-wrapper.c 2010-08-24 22:47:21.000000000 +0200 @@ -298,6 +298,14 @@ ts_interpret_stdin (void) scheme_load_file (&sc, stdin); } +/* ==== modified by Lukasz Czerwinski (lc277...@students.mimuw.edu.pl) */ + +int load_script_file(const char *fname) { + return scheme_file_push(&sc,fname); +} + +/* ==== end of modification ==== */ + gint ts_interpret_string (const gchar *expr) { diff -rup /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/scheme-wrapper.h gimp/plug-ins/script-fu/scheme-wrapper.h --- /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/scheme-wrapper.h 2010-08-24 17:49:15.000000000 +0200 +++ gimp/plug-ins/script-fu/scheme-wrapper.h 2010-08-24 23:09:18.000000000 +0200 @@ -32,6 +32,10 @@ const gchar * ts_get_success_msg (v void ts_interpret_stdin (void); +/* ==== modified by Lukasz Czerwinski (lc277...@students.mimuw.edu.pl) */ +int load_script_file(const char *fname); +/* ==== end of modification ==== */ + /* if the return value is 0, success. error otherwise. */ gint ts_interpret_string (const gchar *expr); diff -rup /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/script-fu-scripts.c gimp/plug-ins/script-fu/script-fu-scripts.c --- /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/script-fu-scripts.c 2010-08-24 17:49:15.000000000 +0200 +++ gimp/plug-ins/script-fu/script-fu-scripts.c 2010-08-25 16:58:31.000000000 +0200 @@ -589,6 +589,7 @@ script_fu_run_command (const gchar *com return success; } +/* modified by Lukasz Czerwinski (lc277...@students.mimuw.edu.pl) */ static void script_fu_load_script (const GimpDatafileData *file_data, gpointer user_data) @@ -602,13 +603,15 @@ script_fu_load_script (const GimpDatafil command = g_strdup_printf ("(load \"%s\")", escaped); g_free (escaped); - if (! script_fu_run_command (command, &error)) +// if (! script_fu_run_command (command, &error)) + if (! load_script_file(file_data->filename)) { gchar *display_name = g_filename_display_name (file_data->filename); gchar *message = g_strdup_printf (_("Error while loading %s:"), display_name); + g_message (message); - g_message ("%s\n\n%s", message, error->message); +// g_message ("%s\n\n%s", message, error->message); g_clear_error (&error); g_free (message); @@ -625,6 +628,7 @@ script_fu_load_script (const GimpDatafil g_free (command); } } +/* end of modifications */ /* * The following function is a GTraverseFunction. diff -rup /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/tinyscheme/scheme.c gimp/plug-ins/script-fu/tinyscheme/scheme.c --- /home/lukasz/OPOS/SOURCE/gimp-git-original/gimp/plug-ins/script-fu/tinyscheme/scheme.c 2010-08-24 17:49:15.000000000 +0200 +++ gimp/plug-ins/script-fu/tinyscheme/scheme.c 2010-08-25 17:08:44.000000000 +0200 @@ -125,6 +125,21 @@ static int utf8_stricmp(const char *s1, return result; } +/* modified by Lukasz Czerwinski (lc277...@students.mimuw.edu.pl) */ +#define stricmp_left_converted utf8_stricmp_left_converted +static int utf8_stricmp_left_converted(const char *case_folded, const char *s2) +{ + char *t2a; + int result; + + t2a = g_utf8_casefold(s2, -1); + + result = strcmp(case_folded, t2a); + g_free(t2a); + return result; +} +/* end of modification */ + #define min(a, b) ((a) <= (b) ? (a) : (b)) #if USE_STRLWR @@ -898,15 +913,18 @@ static INLINE pointer oblist_find_by_nam int location; pointer x; char *s; + gchar *name_case_folded = g_utf8_casefold(name, -1); location = hash_fn(name, ivalue_unchecked(sc->oblist)); for (x = vector_elem(sc->oblist, location); x != sc->NIL; x = cdr(x)) { s = symname(car(x)); /* case-insensitive, per R5RS section 2. */ - if(stricmp(name, s) == 0) { + if(stricmp_left_converted(name_case_folded, s) == 0) { + g_free(name_case_folded); return car(x); } } + g_free(name_case_folded); return sc->NIL; } @@ -1415,6 +1433,14 @@ static void finalize_cell(scheme *sc, po /* ========== Routines for Reading ========== */ +/* modified by Lukasz Czerwinski (lc277...@students.mimuw.edu.pl) */ +int scheme_file_push(scheme *sc, const char *fname) { + int ret = file_push(sc, fname); + file_pop(sc); + return ret; +} +/* end of modification */ + static int file_push(scheme *sc, const char *fname) { FILE *fin = NULL; if (sc->file_i == MAXFIL-1) diff -rup /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/tinyscheme/scheme.h gimp/plug-ins/script-fu/tinyscheme/scheme.h --- /home/lukasz/OPOS/SOURCE/gimp-git-patched/gimp/plug-ins/script-fu/tinyscheme/scheme.h 2010-08-24 17:49:15.000000000 +0200 +++ gimp/plug-ins/script-fu/tinyscheme/scheme.h 2010-08-24 23:07:28.000000000 +0200 @@ -152,6 +152,11 @@ SCHEME_EXPORT pointer scheme_eval(scheme void scheme_set_external_data(scheme *sc, void *p); SCHEME_EXPORT void scheme_define(scheme *sc, pointer env, pointer symbol, pointer value); +/* modified by Lukasz Czerwinski (lc277...@students.mimuw.edu.pl) */ +SCHEME_EXPORT int scheme_file_push(scheme *sc, const char *fname); +/* end of modification */ + + typedef pointer (*foreign_func)(scheme *, pointer); pointer _cons(scheme *sc, pointer a, pointer b, int immutable); Looking forward to your answer, Łukasz Czerwiński
_______________________________________________ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer