From 026e29a042d1eb890e732ea94ba6dd4f5af68917 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Nov 2012 02:38:16 +0000 Subject: [PATCH] simple optimization for library loading, just reduce pointer indirection and use unsigned int's, gives up to 2x overall speedup for loading some libraries. --- source/blender/blenloader/intern/readfile.c | 39 +++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 126c86d3b16..30331713463 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -360,36 +360,39 @@ static void *oldnewmap_lookup_and_inc(OldNewMap *onm, void *addr) } /* 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 */ if (onm->sorted) { OldNew entry_s, *entry; - + entry_s.old = addr; - + entry = bsearch(&entry_s, onm->entries, onm->nentries, sizeof(OldNew), verg_oldnewmap); if (entry) { ID *id = entry->newp; - + if (id && (!lib || id->lib)) { - return entry->newp; + return id; } } } - - for (i = 0; i < onm->nentries; i++) { - OldNew *entry = &onm->entries[i]; - - if (entry->old == addr) { - ID *id = entry->newp; - - if (id && (!lib || id->lib)) { - return entry->newp; + 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, entry = onm->entries; i < nentries; i++, entry++) { + if (entry->old == addr) { + ID *id = id = entry->newp; + if (id && (!lib || id->lib)) { + return id; + } } } }