From: Robert Klemme Date: 2010-08-30T22:45:35+09:00 Subject: Re: Speed issues iterating over chars 2010/8/30 Martin Hansen : >> You could speed up calculation of the regexp by placing this in the >> default block of a Hash, e.g. >> >> RXS = Hash.new {|h,cutoff| h[cutoff] = >> /(?:#{(0..(BASE_SOLEXA+cutoff)).map{|ch|"\\u00%02x" % >> ch}.join("|")})+/ >> >> and then >> >> seq.gsub! RXS[cutoff] do |m| >>   m.downcase! >> end > > > This could be a good idea, but I am not entirely sure if it will work - > at least the current suggestion gives an empty RXS hash. And I am unsure > about what this do? map{|ch|"\\u00%02x" % ch} Just try it out in IRB. This creates a regexp with unicode names. You could however use Fixnum#chr instead, e.g. #{ (0..(BASE_SOLEXA + cutoff)).map {|ch| Regexp.escape(ch.chr)}.join("|") } This gives shorter and more readable strings. > Thinking about this problem I wonder if it would be an idea to create a > mask with transliterate and then use a bitwise operation to downcase. > IIRC you change the case with a bitwise | operation with ' '. It doesn't > look like Ruby have any methods bitwise operations on strings. AFAIK there are none. But you can do irb(main):011:0> s = "aaa" => "aaa" irb(main):012:0> s[0] = (s[0].ord | 0x0F).chr => "o" irb(main):013:0> s => "oaa" Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/