Permalink
Browse files

Fixed Encoding.find performance issue.

In 47f6c18, we changed the encoding map and now store the key
as an upcased symbol, so lookup is very fast.
  • Loading branch information...
1 parent 422359a commit 65b5f2cf5195b77cf22d4d78d10b8d32e378afe5 @brixen brixen committed Aug 6, 2012
Showing with 5 additions and 6 deletions.
  1. +5 −6 kernel/common/encoding.rb
View
@@ -121,13 +121,12 @@ def self.default_internal=(enc)
end
def self.find(name)
- key = StringValue(name).upcase
+ key = StringValue(name).upcase.to_sym
- EncodingMap.each do |n, r|
- if n.to_s.upcase == key
- index = r.last
- return index && EncodingList[index]
- end
+ pair = EncodingMap[key]
+ if pair
+ index = pair.last
+ return index && EncodingList[index]
end
raise ArgumentError, "unknown encoding name - #{name}"

0 comments on commit 65b5f2c

Please sign in to comment.