Index: src/org/jruby/RegexpTranslator.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/RegexpTranslator.java,v
retrieving revision 1.5
diff -u -r1.5 RegexpTranslator.java
--- src/org/jruby/RegexpTranslator.java	22 Feb 2006 04:18:19 -0000	1.5
+++ src/org/jruby/RegexpTranslator.java	8 Apr 2006 09:23:59 -0000
@@ -3,6 +3,9 @@
  */
 package org.jruby;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import java.util.regex.Pattern;
 
 import org.jruby.parser.ReOptions;
@@ -17,10 +20,8 @@
     private static final Pattern OCTAL_MISSING_ZERO_PATTERN = Pattern.compile("\\\\([1-7][0-7]{1,2})");
     
     public Pattern translate(String regex, int options, int javaRegexFlags) {
-    	javaRegexFlags |= translateFlags(options);
-		regex = translatePattern(regex, (javaRegexFlags & Pattern.COMMENTS) != 0);
-		return Pattern.compile(regex, javaRegexFlags);
-	}
+        return getPattern(regex, options, javaRegexFlags);
+    }
 
 	String translatePattern(String regex, boolean commentsAllowed) {
 		regex = COMMENT_PATTERN.matcher(regex).replaceAll("");
@@ -49,4 +50,16 @@
 		return flags;
 	}
 
-}
\ No newline at end of file
+    private Map patternMap = new HashMap();
+    private Pattern getPattern(final String regex, final int options, final int javaRegexFlags) {
+        final String key = regex+"_"+options+"_"+javaRegexFlags;
+        Pattern ptr = (Pattern)patternMap.get(key);
+        if(null == ptr) {
+            final int newJavaRegexFlags = javaRegexFlags | translateFlags(options);
+            final String nRegex = translatePattern(regex, (newJavaRegexFlags & Pattern.COMMENTS) != 0);
+            ptr = Pattern.compile(nRegex,newJavaRegexFlags);
+            patternMap.put(key,ptr);
+        }
+        return ptr;
+    }
+}
