[#7631] 1.3 to 1.4 — Katsuyuki Komatsu <komatsu@...>

小松です。

26 messages 1999/08/12
[#7632] Re: 1.3 to 1.4 — matz@... (Yukihiro Matsumoto) 1999/08/12

まつもと ゆきひろです

[#7634] Re: 1.3 to 1.4 — Katsuyuki Komatsu <komatsu@...> 1999/08/13

小松です。

[#7636] Re: 1.3 to 1.4 — matz@... (Yukihiro Matsumoto) 1999/08/13

まつもと ゆきひろです

[#7638] cvs HEAD (Re: Re: 1.3 to 1.4) — EGUCHI Osamu <eguchi@...> 1999/08/13

えぐち@エスアンドイーです。

[#7647] Re: cvs HEAD (Re: Re: 1.3 to 1.4) — matz@... (Yukihiro Matsumoto) 1999/08/13

まつもと ゆきひろです

[#7641] Re: [ruby-ext:00382] New coerce scheme — keiju@... (石塚圭樹)

けいじゅ@日本ラショナルソフトウェアです.

26 messages 1999/08/13

[ruby-dev:7627] [PATCH] fast jcode.rb

From: WATANABE Hirofumi <watanabe@...>
Date: 1999-08-12 09:57:14 UTC
List: ruby-dev #7627
わたなべです.

もうちょっとだけ jcode.rb を高速化しました.
#2 倍というのは嘘になってしまった.

--- lib/jcode.rb.orig	Tue Jul 27 13:40:43 1999
+++ lib/jcode.rb	Thu Aug 12 18:52:18 1999
@@ -78,16 +78,8 @@
 
-  HashCache = {}
-
-  def expand_ch_hash from, to = ""
-    key = from.intern.to_s + ":" + to.intern.to_s
-    return HashCache[key] if HashCache.key? key
-    afrom = _expand_ch(from)
+  def expand_ch_hash from, to
     h = {}
-    if to.length != 0
-      ato = _expand_ch(to)
-      afrom.each_with_index do |x,i| h[x] = ato[i] || ato[-1] end
-    else
-      afrom.each do |x| h[x] = true end
-    end
-    HashCache[key] = h
+    afrom = _expand_ch(from)
+    ato = _expand_ch(to)
+    afrom.each_with_index do |x,i| h[x] = ato[i] || ato[-1] end
+    h
   end
@@ -98,2 +90,7 @@
 
+  HashCache = {}
+  TrPatternCache = {}
+  DeletePatternCache = {}
+  SqueezePatternCache = {}
+
   public
@@ -103,3 +100,3 @@
 
-    pattern = /[#{bsquote(from)}]/
+    pattern = TrPatternCache[from] ||= /[#{bsquote(from)}]/
     if from[0] == ?^
@@ -108,3 +105,3 @@
     else
-      h = expand_ch_hash(from, to)
+      h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to)
       self.gsub!(pattern) do |c| h[c] end
@@ -118,4 +115,3 @@
   def delete!(del)
-    pattern = /[#{bsquote(del)}]+/
-    self.gsub!(pattern, '')
+    self.gsub!(DeletePatternCache[del] ||= /[#{bsquote(del)}]+/, '')
   end
@@ -129,3 +125,3 @@
       if del
-        /([#{bsquote(del)}])\1+/
+	SqueezePatternCache[del] ||= /([#{bsquote(del)}])\1+/
       else
@@ -143,3 +139,3 @@
 
-    pattern = /([#{bsquote(from)}])\1+/
+    pattern = SqueezePatternCache[from] ||= /([#{bsquote(from)}])\1+"/
     if from[0] == ?^
@@ -148,3 +144,3 @@
     else
-      h = expand_ch_hash(from, to)
+      h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to)
       self.gsub!(pattern) do h[$1] end
@@ -158,3 +154,3 @@
   def chop!
-    self.gsub!(/(?:.|\n)\z/, '')
+    self.gsub!(/(?:.|\r?\n)\z/, '')
   end

In This Thread

Prev Next