Index: src/java/org/apache/lucene/util/StringHelper.java
===================================================================
--- src/java/org/apache/lucene/util/StringHelper.java	(revision 766478)
+++ src/java/org/apache/lucene/util/StringHelper.java	(working copy)
@@ -24,7 +24,9 @@
  * $Id$
  */
 public abstract class StringHelper {
+  public static StringInterner interner = new SimpleStringInterner(1024);
 
+
   /**
    * Compares two byte[] arrays, element by element, and returns the
    * number of elements common to both arrays.
Index: src/java/org/apache/lucene/util/StringInterner.java
===================================================================
--- src/java/org/apache/lucene/util/StringInterner.java	(revision 0)
+++ src/java/org/apache/lucene/util/StringInterner.java	(revision 0)
@@ -0,0 +1,29 @@
+package org.apache.lucene.util;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class StringInterner {
+  /** interns a string according to this StringCreator instance. */
+  public String intern(String s) {
+    return s.intern();
+  }
+
+  /** interns a string according to this StringCreator instance. */  
+  public String intern(char[] arr, int offset, int len) {
+    return intern(new String(arr, offset, len));
+  }
+}

Property changes on: src/java/org/apache/lucene/util/StringInterner.java
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

Index: src/java/org/apache/lucene/util/SimpleStringInterner.java
===================================================================
--- src/java/org/apache/lucene/util/SimpleStringInterner.java	(revision 0)
+++ src/java/org/apache/lucene/util/SimpleStringInterner.java	(revision 0)
@@ -0,0 +1,43 @@
+package org.apache.lucene.util;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * Simple lockless and memory barrier free String intern cache that is guaranteed
+ * to return the same String instance that String.intern() does.
+ */
+public class SimpleStringInterner extends StringInterner {
+  private final String[] cache;
+
+  public SimpleStringInterner(int sz) {
+    cache = new String[BitUtil.nextHighestPowerOfTwo(sz)];
+  }
+
+  // @Override
+  public String intern(String s) {
+    int h = s.hashCode();
+    int slot = h & (cache.length-1);
+    String cachedString = cache[slot];
+    if (cachedString != null && (s==cachedString || s.compareTo(cachedString)==0)) return cachedString;
+    // if there are a lot of misses (table too small) checking hashCode first helps.
+    // if (cachedString!=null && h==cachedString.hashCode() && s.compareTo(cachedString)==0) return cachedString;
+    cachedString = s.intern();
+    cache[slot] = cachedString;
+    return cachedString;
+  }
+}
\ No newline at end of file

Property changes on: src/java/org/apache/lucene/util/SimpleStringInterner.java
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Date Author Id Revision HeadURL
Added: svn:eol-style
   + native

