Use C objectid_generate for ObjectId in addition to ObjectID.
Also, remove broken defined? check from objectid.rb and object_id.rb - it was never doing anything since we require those files at the top of cbson.c.
This commit is contained in:
parent
9eee412213
commit
7702d671ea
@ -949,6 +949,7 @@ void Init_cbson() {
|
|||||||
DigestMD5 = rb_const_get(Digest, rb_intern("MD5"));
|
DigestMD5 = rb_const_get(Digest, rb_intern("MD5"));
|
||||||
|
|
||||||
rb_define_method(ObjectID, "generate", objectid_generate, 0);
|
rb_define_method(ObjectID, "generate", objectid_generate, 0);
|
||||||
|
rb_define_method(ObjectId, "generate", objectid_generate, 0);
|
||||||
|
|
||||||
rb_define_method(rb_cArray, "fast_pack", fast_pack, 0);
|
rb_define_method(rb_cArray, "fast_pack", fast_pack, 0);
|
||||||
}
|
}
|
||||||
|
@ -155,26 +155,24 @@ module BSON
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# We need to define this method only if CBson isn't loaded.
|
# This gets overwritten by the C extension if it loads.
|
||||||
unless defined? CBson
|
def generate
|
||||||
def generate
|
oid = ''
|
||||||
oid = ''
|
|
||||||
|
|
||||||
# 4 bytes current time
|
# 4 bytes current time
|
||||||
time = Time.new.to_i
|
time = Time.new.to_i
|
||||||
oid += [time].pack("N")
|
oid += [time].pack("N")
|
||||||
|
|
||||||
# 3 bytes machine
|
# 3 bytes machine
|
||||||
oid += Digest::MD5.digest(Socket.gethostname)[0, 3]
|
oid += Digest::MD5.digest(Socket.gethostname)[0, 3]
|
||||||
|
|
||||||
# 2 bytes pid
|
# 2 bytes pid
|
||||||
oid += [Process.pid % 0xFFFF].pack("n")
|
oid += [Process.pid % 0xFFFF].pack("n")
|
||||||
|
|
||||||
# 3 bytes inc
|
# 3 bytes inc
|
||||||
oid += [get_inc].pack("N")[1, 3]
|
oid += [get_inc].pack("N")[1, 3]
|
||||||
|
|
||||||
oid.unpack("C12")
|
oid.unpack("C12")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_inc
|
def get_inc
|
||||||
|
@ -158,26 +158,24 @@ module BSON
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# We need to define this method only if CBson isn't loaded.
|
# This gets overwritten by the C extension if it loads.
|
||||||
unless defined? CBson
|
def generate
|
||||||
def generate
|
oid = ''
|
||||||
oid = ''
|
|
||||||
|
|
||||||
# 4 bytes current time
|
# 4 bytes current time
|
||||||
time = Time.new.to_i
|
time = Time.new.to_i
|
||||||
oid += [time].pack("N")
|
oid += [time].pack("N")
|
||||||
|
|
||||||
# 3 bytes machine
|
# 3 bytes machine
|
||||||
oid += Digest::MD5.digest(Socket.gethostname)[0, 3]
|
oid += Digest::MD5.digest(Socket.gethostname)[0, 3]
|
||||||
|
|
||||||
# 2 bytes pid
|
# 2 bytes pid
|
||||||
oid += [Process.pid % 0xFFFF].pack("n")
|
oid += [Process.pid % 0xFFFF].pack("n")
|
||||||
|
|
||||||
# 3 bytes inc
|
# 3 bytes inc
|
||||||
oid += [get_inc].pack("N")[1, 3]
|
oid += [get_inc].pack("N")[1, 3]
|
||||||
|
|
||||||
oid.unpack("C12")
|
oid.unpack("C12")
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_inc
|
def get_inc
|
||||||
|
Loading…
Reference in New Issue
Block a user