minor: ObjectId optimization

This commit is contained in:
Kyle Banker 2010-10-04 12:09:29 -04:00
parent 7ad280c2cb
commit bf10db9b21
6 changed files with 14 additions and 12 deletions

Binary file not shown.

View File

@ -264,10 +264,11 @@ public class RubyBSONCallback implements BSONCallback {
} }
public void gotObjectId( String name , ObjectId id ){ public void gotObjectId( String name , ObjectId id ){
IRubyObject arg = (IRubyObject)RubyString.newString(_runtime, id.toString()); byte[] jbytes = id.toByteArray();
RubyArray arg = ja2ra(jbytes);
Object[] args = new Object[] { arg }; Object[] args = new Object[] { arg };
Object result = JavaEmbedUtils.invokeMethod(_runtime, _rbclsObjectId, "from_string", args, Object.class); Object result = JavaEmbedUtils.invokeMethod(_runtime, _rbclsObjectId, "new", args, Object.class);
_put( name, (RubyObject)result ); _put( name, (RubyObject)result );
} }

View File

@ -319,7 +319,8 @@ public class RubyBSONEncoder extends BSONEncoder {
} }
else { else {
long jval = big.longValue(); long jval = big.longValue();
putLong(name, (Number)jval ); _put( NUMBER_LONG , name );
_buf.writeLong( jval );
} }
} }
@ -530,7 +531,7 @@ public class RubyBSONEncoder extends BSONEncoder {
_put( OID , name ); _put( OID , name );
RubyArray roid = (RubyArray)JavaEmbedUtils.invokeMethod(_runtime, oid, RubyArray roid = (RubyArray)JavaEmbedUtils.invokeMethod(_runtime, oid,
"to_a", new Object[] {}, Object.class); "data", new Object[] {}, Object.class);
byte[] joid = ra2ba( (RubyArray)roid ); byte[] joid = ra2ba( (RubyArray)roid );
_buf.writeInt( convertToInt(joid, 0) ); _buf.writeInt( convertToInt(joid, 0) );

View File

@ -108,6 +108,13 @@ module BSON
@data.dup @data.dup
end end
# Get the array representation without cloning.
#
# @return [Array]
def data
@data
end
# Given a string representation of an ObjectId, return a new ObjectId # Given a string representation of an ObjectId, return a new ObjectId
# with that value. # with that value.
# #
@ -134,13 +141,6 @@ module BSON
str str
end end
def to_e
@data.each do |i|
print i
print ' '
end
end
def inspect def inspect
"BSON::ObjectId('#{to_s}')" "BSON::ObjectId('#{to_s}')"
end end