performance improvement in BERParser#read_ber,
replaced a lot of calls to Symbol#===.
This commit is contained in:
parent
91d5fff39c
commit
58f5db9716
1 changed files with 25 additions and 0 deletions
|
@ -94,6 +94,8 @@ module Net
|
|||
end
|
||||
}
|
||||
|
||||
=begin
|
||||
Replaced this case with if/else because Symbol#=== profiled surprisingly hot.
|
||||
obj = case objtype
|
||||
when :boolean
|
||||
newobj != "\000"
|
||||
|
@ -116,6 +118,29 @@ module Net
|
|||
else
|
||||
raise BerError.new( "unsupported object type: class=#{tagclass}, encoding=#{encoding}, tag=#{tag}" )
|
||||
end
|
||||
=end
|
||||
|
||||
obj = if objtype == :boolean
|
||||
newobj != "\000"
|
||||
elsif objtype == :string
|
||||
(newobj || "").dup
|
||||
elsif objtype == :integer
|
||||
j = 0
|
||||
newobj.each_byte {|b| j = (j << 8) + b}
|
||||
j
|
||||
elsif objtype == :array
|
||||
seq = []
|
||||
sio = StringIO.new( newobj || "" )
|
||||
# Interpret the subobject, but note how the loop
|
||||
# is built: nil ends the loop, but false (a valid
|
||||
# BER value) does not!
|
||||
while (e = sio.read_ber(syntax)) != nil
|
||||
seq << e
|
||||
end
|
||||
seq
|
||||
else
|
||||
raise BerError.new( "unsupported object type: class=#{tagclass}, encoding=#{encoding}, tag=#{tag}" )
|
||||
end
|
||||
|
||||
# Add the identifier bits into the object if it's a String or an Array.
|
||||
# We can't add extra stuff to Fixnums and booleans, not that it makes much sense anyway.
|
||||
|
|
Loading…
Reference in a new issue