[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13485] trunk/blender/source/blender/ blenloader/intern: Speedup of filereading: when using large libraries ( referenced data from
Ton Roosendaal
ton at blender.org
Wed Jan 30 19:18:34 CET 2008
Revision: 13485
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13485
Author: ton
Date: 2008-01-30 19:18:33 +0100 (Wed, 30 Jan 2008)
Log Message:
-----------
Speedup of filereading: when using large libraries (referenced data from
other blend files) lookups of data slowed down tremendously.
Added another bsearch for speedup. Makes a difference here (200+ MB files)!
Modified Paths:
--------------
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/blenloader/intern/readfile.h
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2008-01-30 17:58:13 UTC (rev 13484)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2008-01-30 18:18:33 UTC (rev 13485)
@@ -727,8 +727,8 @@
BHead *blo_nextbhead(FileData *fd, BHead *thisblock)
{
- BHeadN *new_bhead = 0;
- BHead *bhead = 0;
+ BHeadN *new_bhead = NULL;
+ BHead *bhead = NULL;
if (thisblock) {
// bhead is actually a sub part of BHeadN
@@ -1033,7 +1033,9 @@
oldnewmap_free(fd->imamap);
if (fd->libmap && !(fd->flags & FD_FLAGS_NOT_MY_LIBMAP))
oldnewmap_free(fd->libmap);
-
+ if (fd->bheadmap)
+ MEM_freeN(fd->bheadmap);
+
MEM_freeN(fd);
}
}
@@ -7485,7 +7487,7 @@
/* do before read_libraries, but skip undo case */
// if(fd->memfile==NULL) (the mesh shuffle hacks don't work yet? ton)
do_versions(fd, NULL, bfd->main);
-
+
read_libraries(fd, &fd->mainlist);
blo_join_main(&fd->mainlist);
@@ -7504,6 +7506,43 @@
/* ************* APPEND LIBRARY ************** */
+struct bheadsort {
+ BHead *bhead;
+ void *old;
+};
+
+static int verg_bheadsort(const void *v1, const void *v2)
+{
+ const struct bheadsort *x1=v1, *x2=v2;
+
+ if( x1->old > x2->old) return 1;
+ else if( x1->old < x2->old) return -1;
+ return 0;
+}
+
+static void sort_bhead_old_map(FileData *fd)
+{
+ BHead *bhead;
+ struct bheadsort *bhs;
+ int tot= 0;
+
+ for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead))
+ tot++;
+
+ fd->tot_bheadmap= tot;
+ if(tot==0) return;
+
+ bhs= fd->bheadmap= MEM_mallocN(tot*sizeof(struct bheadsort), "bheadsort");
+
+ for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead), bhs++) {
+ bhs->bhead= bhead;
+ bhs->old= bhead->old;
+ }
+
+ qsort(fd->bheadmap, tot, sizeof(struct bheadsort), verg_bheadsort);
+
+}
+
static BHead *find_previous_lib(FileData *fd, BHead *bhead)
{
for (; bhead; bhead= blo_prevbhead(fd, bhead))
@@ -7516,14 +7555,24 @@
static BHead *find_bhead(FileData *fd, void *old)
{
BHead *bhead;
-
+ struct bheadsort *bhs, bhs_s;
+
if (!old)
return NULL;
- for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead))
- if (bhead->old==old)
- return bhead;
+ if (fd->bheadmap==NULL)
+ sort_bhead_old_map(fd);
+
+ bhs_s.old= old;
+ bhs= bsearch(&bhs_s, fd->bheadmap, fd->tot_bheadmap, sizeof(struct bheadsort), verg_bheadsort);
+ if(bhs)
+ return bhs->bhead;
+
+// for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead))
+// if (bhead->old==old)
+// return bhead;
+
return NULL;
}
Modified: trunk/blender/source/blender/blenloader/intern/readfile.h
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.h 2008-01-30 17:58:13 UTC (rev 13484)
+++ trunk/blender/source/blender/blenloader/intern/readfile.h 2008-01-30 18:18:33 UTC (rev 13485)
@@ -37,6 +37,7 @@
struct OldNewMap;
struct MemFile;
+struct bheadsort;
typedef struct FileData {
// linked list of BHeadN's
@@ -76,6 +77,9 @@
struct OldNewMap *libmap;
struct OldNewMap *imamap;
+ struct bheadsort *bheadmap;
+ int tot_bheadmap;
+
ListBase mainlist;
/* ick ick, used to return
More information about the Bf-blender-cvs
mailing list