Index: src/java/org/apache/lucene/util/StringHelper.java
===================================================================
--- src/java/org/apache/lucene/util/StringHelper.java	(revision 769439)
+++ 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,8);
 
+
   /**
    * 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,81 @@
+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 as String.intern() does.
+ */
+public class SimpleStringInterner extends StringInterner {
+
+  private static class Entry {
+    final private String str;
+    final private int hash;
+    private Entry next;
+    private Entry(String str, int hash, Entry next) {
+      this.str = str;
+      this.hash = hash;
+      this.next = next;
+    }
+  }
+
+  private final Entry[] cache;
+  private final int maxChainLength;
+
+  public SimpleStringInterner(int tableSize, int maxChainLength) {
+    cache = new Entry[Math.max(1,BitUtil.nextHighestPowerOfTwo(tableSize))];
+    this.maxChainLength = Math.max(2,maxChainLength);
+  }
+
+  // @Override
+  public String intern(String s) {
+    Entry[] arr = cache;
+    int h = s.hashCode();
+    // TODO: it may be worth augmenting the string hash
+    // if the lower bits need better distribution.
+    int slot = h & (arr.length-1);
+
+    Entry first = cache[slot];
+    Entry nextToLast = null;
+    Entry e = first;
+
+    int chainLength = 0;
+    for(;;) {
+      // insertion-order cache: add new entry at head
+      if (e==null) {
+        s = s.intern();
+        arr[slot] = new Entry(s.intern(), h, first);
+        if (chainLength >= maxChainLength) {
+          // prune last entry
+          nextToLast.next = null;
+        }
+        return s;
+      }
+
+      if (e.str == s || (e.hash == h && e.str.compareTo(s)==0)) {
+        return e.str;
+      }
+
+      chainLength++;
+      if (e.next != null) {
+        nextToLast = e;
+      }
+      e = e.next;
+    }
+  }
+}
\ 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

