A ConsString Gotcha
Tal Liron
tal.liron at threecrickets.com
Sun Oct 13 09:41:46 PDT 2013
Your proposal solves the generics problem nicely enough, but many 3rd
party libraries out there have methods with Object argument signatures.
I still think that blanket conversion is best, configurable with a flag.
The performance issue might be fixable like so: if ever a ConsString
needs to be converted to a String, it would happen once and only once,
effectively internally replacing the ConsString with a String instance.
The performance hit would be momentary. And again, can be disabled with
a flag.
On 10/14/2013 12:28 AM, Jim Laskey (Oracle) wrote:
> The complication there is that every time you have an Object argument/field you would have to have an if instanceof ConsString cast String sequence, which is a huge performance hit. ConsString was introduced to significantly improve performance (high frequency operation), so it's a bit of a dilemma. The team has debated this several times. It might be better in the long run to be able to properly declare the HashMap with something like;
>
> var StringHashMap = Java.type("java.util.HashMap<java.lang.String, java.lang.Object>");
>
> or even better
>
> var JObject = Java.type("java.lang.Object");
> var JString = Java.type("java.lang.String");
> var StringHashMap = Java.type("java.util.HashMap", JString, JObject);
>
More information about the nashorn-dev
mailing list