1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[smjs] I did not test it, but suppose that JS_GetStringLength is faster than strlen.

This commit is contained in:
Witold Filipczyk 2022-06-18 21:11:53 +02:00
parent 50b1406cf0
commit 21cf493377

View File

@ -108,12 +108,16 @@ cache_entry_get_property_content(JSContext *ctx, unsigned int argc, JS::Value *v
} }
static char * static char *
jsval_to_Latin1(JSContext *ctx, JS::HandleValue hvp) jsval_to_Latin1(JSContext *ctx, JS::HandleValue hvp, size_t *length)
{ {
/* Memory must be freed in caller */ /* Memory must be freed in caller */
JSString *st = JS::ToString(ctx, hvp); JSString *st = JS::ToString(ctx, hvp);
JS::UniqueChars chars = JS_EncodeStringToLatin1(ctx, st); JS::UniqueChars chars = JS_EncodeStringToLatin1(ctx, st);
if (length) {
*length = JS_GetStringLength(st);
}
return null_or_stracpy(chars.get()); return null_or_stracpy(chars.get());
} }
@ -146,8 +150,7 @@ cache_entry_set_property_content(JSContext *ctx, unsigned int argc, JS::Value *v
* eventually unlock the object. */ * eventually unlock the object. */
object_lock(cached); object_lock(cached);
str = jsval_to_Latin1(smjs_ctx, args[0]); str = jsval_to_Latin1(smjs_ctx, args[0], &len);
len = strlen(str);
add_fragment(cached, 0, str, len); add_fragment(cached, 0, str, len);
normalize_cache_entry(cached, len); normalize_cache_entry(cached, len);