Skip to content

Commit

Permalink
Use unf on all versions; native is more than 11x slower
Browse files Browse the repository at this point in the history
  • Loading branch information
pzb committed Aug 9, 2017
1 parent efee967 commit 933414a
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions lib/simpleidn.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'simpleidn/version'
require 'simpleidn/uts46mapping'

# If no known method for normalization is available, load unf to get one
unless ''.respond_to?(:unicode_normalize) || ''.respond_to?(:to_nfc)
require 'unf'
end
require 'unf'

module SimpleIDN
# The ConversionError is raised when an error occurs during a
Expand Down Expand Up @@ -227,9 +223,6 @@ def uts46map(str, transitional = false)
mapped = str.codepoints.map { |cp| UTS64MAPPING.fetch(cp, cp) }
mapped = mapped.map { |cp| TRANSITIONAL.fetch(cp, cp) } if transitional
mapped = mapped.flatten.map { |cp| cp.chr(Encoding::UTF_8) }.join(EMPTY)

# Prefer the internal method if available (e.g. Ruby 2.2 or later)
return mapped.unicode_normalize(:nfc) if mapped.respond_to? :unicode_normalize
mapped.to_nfc
end

Expand Down

0 comments on commit 933414a

Please sign in to comment.