Skip to content

Instantly share code, notes, and snippets.

@tduehr
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tduehr/9279955 to your computer and use it in GitHub Desktop.
Save tduehr/9279955 to your computer and use it in GitHub Desktop.
prototype of caching RubyString objects created from Java string literals
class RubyString {
//...
private final ObjectProxyCache<IRubyObject,RubyString> stringCache =
new ObjectProxyCache<Object,RubyString>(ObjectProxyCache.ReferenceType.SOFT) {
public IRubyObject allocateProxy(CharSequence str, RubyClass clazz) {
return RubyString.newString(clazz.getRuntime(), str);
}
};
public RubyString cachedString(CharSequence s){
return stringCache.get(s);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment