用于创建优化属性键的函数
【Functions to create optimized property keys】
许多 JavaScript 引擎,包括 V8,使用内化字符串作为键来设置和获取属性值。它们通常使用哈希表来创建和查询这些字符串。虽然每次创建键时会增加一些开销,但之后可以通过比较字符串指针而不是整个字符串来提高性能。
【Many JavaScript engines including V8 use internalized strings as keys to set and get property values. They typically use a hash table to create and lookup such strings. While it adds some cost per key creation, it improves the performance after that by enabling comparison of string pointers instead of the whole strings.】
如果一个新的 JavaScript 字符串打算用作属性键,那么对于某些 JavaScript 引擎来说,使用本节中的函数会更高效。否则,请使用 napi_create_string_utf8 或 node_api_create_external_string_utf8 系列函数,因为使用属性键创建方法创建/存储字符串可能会有额外开销。
【If a new JavaScript string is intended to be used as a property key, then for
some JavaScript engines it will be more efficient to use the functions in this
section. Otherwise, use the napi_create_string_utf8 or
node_api_create_external_string_utf8 series functions as there may be
additional overhead in creating/storing strings with the property key
creation methods.】