simple optimization for library loading, just reduce pointer indirection and use unsigned int's, gives up to 2x overall speedup for loading some libraries.

This commit is contained in:
Campbell Barton 2012-11-10 02:38:16 +00:00
parent 9117828902
commit 026e29a042

@ -362,9 +362,9 @@ static void *oldnewmap_lookup_and_inc(OldNewMap *onm, void *addr)
/* for libdata, nr has ID code, no increment */ /* for libdata, nr has ID code, no increment */
static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib) static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib)
{ {
int i; if (addr == NULL) {
return NULL;
if (addr == NULL) return NULL; }
/* lasthit works fine for non-libdata, linking there is done in same sequence as writing */ /* lasthit works fine for non-libdata, linking there is done in same sequence as writing */
if (onm->sorted) { if (onm->sorted) {
@ -377,19 +377,22 @@ static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib)
ID *id = entry->newp; ID *id = entry->newp;
if (id && (!lib || id->lib)) { if (id && (!lib || id->lib)) {
return entry->newp; return id;
} }
} }
} }
else {
/* note, this can be a bottle neck when loading some files */
unsigned int nentries = (unsigned int)onm->nentries;
unsigned int i;
OldNew *entry;
for (i = 0; i < onm->nentries; i++) { for (i = 0, entry = onm->entries; i < nentries; i++, entry++) {
OldNew *entry = &onm->entries[i];
if (entry->old == addr) { if (entry->old == addr) {
ID *id = entry->newp; ID *id = id = entry->newp;
if (id && (!lib || id->lib)) { if (id && (!lib || id->lib)) {
return entry->newp; return id;
}
} }
} }
} }