Cache hostname digest at load time
This brings pure-ruby BSON::ObjectId performance more in line with that of the cbson extension.
This commit is contained in:
parent
4a319f508f
commit
5572663d40
@ -32,6 +32,7 @@ module BSON
|
|||||||
class ObjectId
|
class ObjectId
|
||||||
@@lock = Mutex.new
|
@@lock = Mutex.new
|
||||||
@@index = 0
|
@@index = 0
|
||||||
|
@@hostname_digest = Digest::MD5.digest(Socket.gethostname)[0, 3]
|
||||||
|
|
||||||
attr_accessor :data
|
attr_accessor :data
|
||||||
|
|
||||||
@ -185,7 +186,7 @@ module BSON
|
|||||||
oid += [t].pack("N")
|
oid += [t].pack("N")
|
||||||
|
|
||||||
# 3 bytes machine
|
# 3 bytes machine
|
||||||
oid += Digest::MD5.digest(Socket.gethostname)[0, 3]
|
oid += @@hostname_digest
|
||||||
|
|
||||||
# 2 bytes pid
|
# 2 bytes pid
|
||||||
oid += [Process.pid % 0xFFFF].pack("n")
|
oid += [Process.pid % 0xFFFF].pack("n")
|
||||||
|
Loading…
Reference in New Issue
Block a user