Skip to content

Commit

Permalink
Cheaper clearing of primitive tables if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed May 26, 2016
1 parent b669ced commit eda2a3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -163,7 +163,10 @@ protected int index( int index )
@Override
public void clear()
{
clearTable();
if ( size > 0 )
{
clearTable();
}
super.clear();
}
}
Expand Up @@ -39,14 +39,22 @@ protected UnsafeTable( int capacity, int bytesPerKey, VALUE valueMarker )
this.valueMarker = valueMarker;
this.dataSize = (long)this.capacity*bytesPerEntry;
this.address = UnsafeUtil.allocateMemory( dataSize );
clear();
clearTable();
}

private void clearTable()
{
UnsafeUtil.setMemory( address, dataSize, (byte)-1 );
}

@Override
public void clear()
{
if ( size > 0 )
{
clearTable();
}
super.clear();
UnsafeUtil.setMemory( address, dataSize, (byte)-1 );
}

@Override
Expand Down

0 comments on commit eda2a3e

Please sign in to comment.