On Wed, Sep 11, 2013 at 07:09:29PM +0200, Michael Schroeder wrote: > There are different (and easier) ways to fix this: > > - you can always put an empty string into the pool, it would always > have id 1. This simplifies the dummy entry check to: > if (i != 1 && str[0] == 0) > > - you could get rid of the dummy entries and remove the > rpmstrPoolStrlen() function. It's only used 5 times in the code > and calling strlen() on the returned string does not cost much.
Having slept one night I think the best way is really to remove the dummy entries. You can still have rpmstrPoolStrlen() if you start each chunk with a non-zero character, e.g. \377first_string_in_chunk\0...\0last_string_in_chunk\0 ^ ^ You can then change rpmPoolStrlen to: size_t rpmstrPoolStrlen(rpmstrPool pool, rpmsid sid) { size_t slen = 0; if (pool && sid > 0 && sid <= pool->offs_size) { const char *str = pool->offs[sid]; const char *nextstr = pool->offs[sid + 1]; if (nextstr[-1] == 0) slen = nextstr - str - 1; else slen = strlen(str); /* last string in chunk */ } return slen; } So rpmstrPoolStrlen() is as fast as before except for the last sting in the chunk. But maybe simply replacing the rpmstrPoolStrlen() calls with (inlined) strlen() calls is even faster. Cheers, Michael. -- Michael Schroeder m...@suse.de SUSE LINUX Products GmbH, GF Jeff Hawn, HRB 16746 AG Nuernberg main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);} _______________________________________________ Rpm-maint mailing list Rpm-maint@lists.rpm.org http://lists.rpm.org/mailman/listinfo/rpm-maint