MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve fast path

+13 -4
+13 -4
src/silver/ops/property.h
··· 342 342 ant_offset_t byte_len = 0; 343 343 ant_offset_t str_off = vstr(js, str, &byte_len); 344 344 const char *str_data = (const char *)(uintptr_t)(str_off); 345 - size_t char_bytes = 0; 346 - int byte_offset = utf16_index_to_byte_offset(str_data, byte_len, idx, &char_bytes); 347 - if (byte_offset < 0 || char_bytes == 0) { 345 + 346 + uint32_t code_unit = utf16_code_unit_at(str_data, byte_len, idx); 347 + if (code_unit == 0xFFFFFFFF) { 348 348 *out = js_mkundef(); 349 349 return true; 350 350 } 351 351 352 - *out = js_mkstr(js, str_data + byte_offset, char_bytes); 352 + char buf[4]; 353 + size_t out_len = 0; 354 + if (code_unit >= 0xD800 && code_unit <= 0xDFFF) { 355 + buf[0] = (char)(0xE0 | (code_unit >> 12)); 356 + buf[1] = (char)(0x80 | ((code_unit >> 6) & 0x3F)); 357 + buf[2] = (char)(0x80 | (code_unit & 0x3F)); 358 + out_len = 3; 359 + } else out_len = (size_t)utf8_encode(code_unit, buf); 360 + *out = js_mkstr(js, buf, out_len); 361 + 353 362 return true; 354 363 } 355 364