Markus Amsler : dbghelp: Speed up vector_add by avoiding pool_realloc
calls . Remove no longer needed pool_realloc.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue May 15 14:02:20 CDT 2007
Module: wine
Branch: master
Commit: f94127f2ca4af485bdb4d55128d1d6311048ac33
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f94127f2ca4af485bdb4d55128d1d6311048ac33
Author: Markus Amsler <markus.amsler at oribi.org>
Date: Tue May 15 02:04:57 2007 +0200
dbghelp: Speed up vector_add by avoiding pool_realloc calls. Remove no longer needed pool_realloc.
---
dlls/dbghelp/dbghelp_private.h | 3 +-
dlls/dbghelp/storage.c | 47 ++++++++++++++-------------------------
2 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index a84d91c..5ee22c3 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -44,8 +44,6 @@ struct pool /* poor's man */
void pool_init(struct pool* a, unsigned arena_size);
void pool_destroy(struct pool* a);
void* pool_alloc(struct pool* a, unsigned len);
-/* void* pool_realloc(struct pool* a, void* p,
- unsigned old_size, unsigned new_size); */
char* pool_strdup(struct pool* a, const char* str);
struct vector
@@ -55,6 +53,7 @@ struct vector
unsigned shift;
unsigned num_elts;
unsigned num_buckets;
+ unsigned buckets_allocated;
};
void vector_init(struct vector* v, unsigned elt_sz, unsigned bucket_sz);
diff --git a/dlls/dbghelp/storage.c b/dlls/dbghelp/storage.c
index e196143..602d97f 100644
--- a/dlls/dbghelp/storage.c
+++ b/dlls/dbghelp/storage.c
@@ -101,33 +101,6 @@ void* pool_alloc(struct pool* pool, unsigned len)
return ret;
}
-static struct pool_arena* pool_is_last(const struct pool* pool, const void* p, unsigned old_size)
-{
- struct pool_arena* arena;
-
- for (arena = pool->first; arena; arena = arena->next)
- {
- if (arena->current == (const char*)p + old_size) return arena;
- }
- return NULL;
-}
-
-static void* pool_realloc(struct pool* pool, void* p, unsigned old_size, unsigned new_size)
-{
- struct pool_arena* arena;
- void* new;
-
- if ((arena = pool_is_last(pool, p, old_size)) &&
- (char*)p + new_size <= (char*)arena + pool->arena_size)
- {
- arena->current = (char*)p + new_size;
- return p;
- }
- if ((new = pool_alloc(pool, new_size)) && old_size)
- memcpy(new, p, min(old_size, new_size));
- return new;
-}
-
char* pool_strdup(struct pool* pool, const char* str)
{
char* ret;
@@ -155,6 +128,7 @@ void vector_init(struct vector* v, unsigned esz, unsigned bucket_sz)
default: assert(0);
}
v->num_buckets = 0;
+ v->buckets_allocated = 0;
v->num_elts = 0;
}
@@ -180,9 +154,22 @@ void* vector_add(struct vector* v, struct pool* pool)
assert(v->num_elts > ncurr);
if (ncurr == (v->num_buckets << v->shift))
{
- v->buckets = pool_realloc(pool, v->buckets,
- v->num_buckets * sizeof(void*),
- (v->num_buckets + 1) * sizeof(void*));
+ if(v->num_buckets == v->buckets_allocated)
+ {
+ /* Double the bucket cache, so it scales well with big vectors.*/
+ unsigned new_reserved;
+ void* new;
+
+ new_reserved = 2*v->buckets_allocated;
+ if(new_reserved == 0) new_reserved = 1;
+
+ /* Don't even try to resize memory.
+ Pool datastructure is very inefficient with reallocs. */
+ new = pool_alloc(pool, new_reserved * sizeof(void*));
+ memcpy(new, v->buckets, v->buckets_allocated * sizeof(void*));
+ v->buckets = new;
+ v->buckets_allocated = new_reserved;
+ }
v->buckets[v->num_buckets] = pool_alloc(pool, v->elt_size << v->shift);
return v->buckets[v->num_buckets++];
}
More information about the wine-cvs
mailing list