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:
Bernerd Schaefer 2011-06-29 12:31:10 +02:00
parent 4a319f508f
commit 5572663d40
1 changed files with 2 additions and 1 deletions

View File

@ -32,6 +32,7 @@ module BSON
class ObjectId
@@lock = Mutex.new
@@index = 0
@@hostname_digest = Digest::MD5.digest(Socket.gethostname)[0, 3]
attr_accessor :data
@ -185,7 +186,7 @@ module BSON
oid += [t].pack("N")
# 3 bytes machine
oid += Digest::MD5.digest(Socket.gethostname)[0, 3]
oid += @@hostname_digest
# 2 bytes pid
oid += [Process.pid % 0xFFFF].pack("n")