14. dec. 2010 19.15 skrev Jeremy <[email protected]>: > When is it appropriate to use String::NewSymbol() rather than > String::New()? I assume that symbols are mainly for oft-reused > property names; is this correct? Is obj- >>Set(String::NewSymbol('foo'), value) somehow more efficient than obj- >>Set(String::New('foo'), value)?
A symbol is just a string that is marked with a bit and which is automatically canonicalized. There cannot be two symbols with the same character sequence in the system. There are some places in the VM where you can only use symbols, not strings. Property names are one of these. The way it normally works is that if you pass a string it might be converted inplace into a symbol or the already existing symbol may be used instead. The second of those takes some time, so if you know you will be using the same string again and again you may as well get hold of the symbol from the start. This will save the VM the trouble of finding the correct symbol every time you pass your string. > > Is a Symbol effected differently by the current HandleScope? I often > see people using Persistent symbols for property names and event > identifiers; is this internally more efficient than using string > values? Handles don't care about the difference between symbols and other strings. > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > -- Erik Corry, Software Engineer Google Denmark ApS - Frederiksborggade 20B, 1 sal, 1360 København K - Denmark - CVR nr. 28 86 69 84 -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
