Permalink
Browse files

Add a CHM to SymbolTable for Bytelist => Symbol. Fixes #300.

  • Loading branch information...
1 parent eb59845 commit a914eb9cc2a802b024f2ad8ca424a657f205080e @headius headius committed with Prathamesh Sonpatki Sep 18, 2012
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/org/jruby/RubySymbol.java
@@ -42,6 +42,7 @@
import static org.jruby.util.StringSupport.codeLength;
import static org.jruby.util.StringSupport.codePoint;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import org.jcodings.Encoding;
@@ -652,6 +653,7 @@ private static ByteList symbolBytesFromString(Ruby runtime, String internedSymbo
private final ReentrantLock tableLock = new ReentrantLock();
private volatile SymbolEntry[] symbolTable;
+ private final ConcurrentHashMap<ByteList, RubySymbol> bytelistTable = new ConcurrentHashMap<ByteList, RubySymbol>(100, 0.75f, Runtime.getRuntime().availableProcessors());
private int size;
private int threshold;
private final float loadFactor;
@@ -693,15 +695,27 @@ public RubySymbol getSymbol(String name) {
}
public RubySymbol getSymbol(ByteList bytes) {
+ RubySymbol symbol = bytelistTable.get(bytes);
+ if (symbol != null) return symbol;
+
String name = bytes.toString();
int hash = name.hashCode();
SymbolEntry[] table = symbolTable;
for (SymbolEntry e = getEntryFromTable(table, hash); e != null; e = e.next) {
- if (isSymbolMatch(name, hash, e)) return e.symbol;
+ if (isSymbolMatch(name, hash, e)) {
+ symbol = e.symbol;
+ break;
+ }
+ }
+
+ if (symbol == null) {
+ symbol = createSymbol(name, bytes, hash, table);
}
- return createSymbol(name, bytes, hash, table);
+ bytelistTable.put(bytes, symbol);
+
+ return symbol;
}
public RubySymbol fastGetSymbol(String internedName) {

0 comments on commit a914eb9

Please sign in to comment.