make ByteBufferUtil.clone thread-safe

patch by tjake and jbellis for CASSANDRA-1847

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1045230 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2010-12-13 16:56:16 +00:00
parent 6e92020a86
commit 92b166df95
2 changed files with 20 additions and 4 deletions

View File

@ -8,6 +8,7 @@ dev
* cli defaults to bytestype for subcomparator when creating
column families (CASSANDRA-1835)
* unregister index MBeans when index is dropped (CASSANDRA-1843)
* make ByteBufferUtil.clone thread-safe (CASSANDRA-1847)
0.7.0-rc2

View File

@ -101,11 +101,26 @@ public class ByteBufferUtil
public static ByteBuffer clone(ByteBuffer o)
{
assert o != null;
if (o.remaining() == 0)
return FBUtilities.EMPTY_BYTE_BUFFER;
ByteBuffer clone = ByteBuffer.allocate(o.remaining());
o.mark();
clone.put(o);
o.reset();
clone.flip();
if (o.isDirect())
{
for (int i = o.position(); i < o.limit(); i++)
{
clone.put(o.get(i));
}
clone.flip();
}
else
{
System.arraycopy(o.array(), o.arrayOffset() + o.position(), clone.array(), 0, o.remaining());
}
return clone;
}
}