Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
avoid 3 virtual calls in _aaGetX and zero only memory not being set a…
Browse files Browse the repository at this point in the history
…nyways

 - yields ~5% faster value insertion in the benchmarks
  • Loading branch information
MartinNowak committed Oct 12, 2011
1 parent c8e645c commit 3a625b3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/rt/aaA.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private
}

extern (C) void* gc_malloc( size_t sz, uint ba = 0 );
extern (C) void* gc_calloc( size_t sz, uint ba = 0 );
extern (C) void gc_free( void* p );

// Convenience function to make sure the NO_INTERIOR gets set on the
Expand Down Expand Up @@ -245,7 +244,7 @@ body
aaA *e;
//printf("keyti = %p\n", keyti);
//printf("aa = %p\n", aa);
auto keysize = aligntsize(keyti.tsize());
immutable keytitsize = keyti.tsize();

if (!aa.a)
{ aa.a = new BB();
Expand All @@ -272,11 +271,13 @@ body

// Not found, create new elem
//printf("create new one\n");
size_t size = aaA.sizeof + keysize + valuesize;
e = cast(aaA *) gc_calloc(size);
memcpy(e + 1, pkey, keyti.tsize);
memset(cast(byte*)(e + 1) + keyti.tsize, 0, keysize - keyti.tsize);
size_t size = aaA.sizeof + aligntsize(keytitsize) + valuesize;
e = cast(aaA *) gc_malloc(size);
e.next = null;
e.hash = key_hash;
ubyte* ptail = cast(ubyte*)(e + 1);
memcpy(ptail, pkey, keytitsize);
memset(ptail + aligntsize(keytitsize), 0, valuesize); // zero value
*pe = e;

auto nodes = ++aa.a.nodes;
Expand All @@ -288,7 +289,7 @@ body
}

Lret:
return cast(void *)(e + 1) + keysize;
return cast(void *)(e + 1) + aligntsize(keytitsize);
}


Expand Down

0 comments on commit 3a625b3

Please sign in to comment.