mirror of https://github.com/apache/cassandra
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:
parent
6e92020a86
commit
92b166df95
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue