Hi, I made a tiny change to string-related code in src/utli/string.c and /src/util/conv.c, following Pasky's TODO comments regarding optimization. Below there's the related diff output.
I feel a bit embarrassed for asking. Since this is the first code I try to submit for an open source project, I don't have much of a clue on how to do it properly. What should I do next? regards, Andrea ==============DIFF OUTPUT ======================== diff -ru old/elinks/src/util/conv.c elinks/src/util/conv.c --- old/elinks/src/util/conv.c 2009-06-07 14:44:19.000000000 +0200 +++ elinks/src/util/conv.c 2009-06-07 20:37:47.000000000 +0200 @@ -340,17 +340,34 @@ return string; } -/* TODO Optimize later --pasky */ + struct string * add_quoted_to_string(struct string *string, const unsigned char *src, int len) { - for (; len; len--, src++) { - if (isquote(*src) || *src == '\\') - add_char_to_string(string, '\\'); - add_char_to_string(string, *src); - } - return string; + if (len > 0) + { + const unsigned char *c; + int i; + unsigned int old_length = string->length; + + + for(i = len, c = src; i; i--, c++){ + if (isquote(*c) || *c =='\\') + string->length++; + string->length++; + }; + + realloc_string(string, string->length); + enforce_null_terminated(*string); + + for (i = old_length, c = src ; i < string->length; i++, c++) { + if (isquote(*src) || *c == '\\') + string->source[i++] = '\\'; + string->source[i]= (*c); + } + }; + return string; } struct string * diff -ru old/elinks/src/util/string.c elinks/src/util/string.c --- old/elinks/src/util/string.c 2009-06-07 14:44:19.000000000 +0200 +++ elinks/src/util/string.c 2009-06-07 20:39:20.000000000 +0200 @@ -294,9 +294,6 @@ /* The new string utilities: */ -/* TODO Currently most of the functions use add_bytes_to_string() as a backend - * instead we should optimize each function. */ - NONSTATIC_INLINE struct string * #ifdef DEBUG_MEMLEAK init_string__(const unsigned char *file, int line, struct string *string) @@ -351,7 +348,16 @@ if (!*source) return string; - return add_bytes_to_string(string, source, strlen(source)); + size_t newlength = string->length + strlen(source); + + realloc_string(string, newlength); + + memcpy(&(string->source[string->length]), source, newlength - string->length); + + string->length = newlength; + string->source[string->length] = '\0'; + + return string; } /** @relates string */ @@ -385,7 +391,16 @@ if (!from->length) return string; /* optimization only */ - return add_bytes_to_string(string, from->source, from->length); + size_t newlength = string->length + from->length; + + realloc_string(string, newlength); + + memcpy(&(string->source[string->length]), from->source, newlength - string->length); + + string->length = newlength; + string->source[string->length] = '\0'; + + return string; } /** @relates string */ _______________________________________________ elinks-dev mailing list elinks-dev@linuxfromscratch.org http://linuxfromscratch.org/mailman/listinfo/elinks-dev