Skip to content
  • Philip Chimento's avatar
    js: Use JS_EncodeStringToUTF8() directly where advantageous · 6aafd113
    Philip Chimento authored
    We have gjs_string_to_utf8() which takes a JS::Value, checks if it holds
    a string and throws an exception if not, then converts to a JSString and
    calls JS_EncodeStringToUTF8() on it. This fixes some inefficient uses of
    that function.
    
    In a few cases the typecheck was repeated before calling
    gjs_string_to_utf8(), the outer typecheck is simply removed.
    
    In other cases the typecheck was already guaranteed because we wanted to
    take a different code path when the value didn't hold a string, in these
    cases we inline the value.toString() call and the JS_EncodeStringToUTF8()
    call.
    
    In many other cases we were converting a JSString to JS::Value only to
    pass it to gjs_string_to_utf8() so we could convert it back to JSString.
    In these cases we just use JS_EncodeStringToUTF8() directly.
    
    gjs_string_to_utf8() is still useful when looking up a property on an
    object that is supposed to be a string, and it's still used quite often
    in the codebase.
    6aafd113