Bug 1511401 part 3. Inline the fast (no error) path of requireAtLeast. r=nbp

We don't want to pay the cost of a function call here in DOM bindings.
This commit is contained in:
Boris Zbarsky 2018-12-10 14:13:05 -05:00
Родитель 7f5c7dd8aa
Коммит d28b50be98
2 изменённых файлов: 28 добавлений и 17 удалений

Просмотреть файл

@ -309,13 +309,28 @@ class MOZ_STACK_CLASS CallArgs
return args;
}
/*
* Helper for requireAtLeast to report the actual exception.
*/
static JS_PUBLIC_API void reportMoreArgsNeeded(JSContext* cx,
const char* fnname,
unsigned required,
unsigned actual);
public:
/*
* Returns true if there are at least |required| arguments passed in. If
* false, it reports an error message on the context.
*/
JS_PUBLIC_API bool requireAtLeast(JSContext* cx, const char* fnname,
unsigned required) const;
JS_PUBLIC_API inline bool requireAtLeast(JSContext* cx, const char* fnname,
unsigned required) const {
if (MOZ_LIKELY(required <= length())) {
return true;
}
reportMoreArgsNeeded(cx, fnname, required, length());
return false;
}
};
MOZ_ALWAYS_INLINE CallArgs CallArgsFromVp(unsigned argc, Value* vp) {

Просмотреть файл

@ -124,21 +124,17 @@ using JS::SourceText;
#define JS_ADDRESSOF_VA_LIST(ap) (&(ap))
#endif
JS_PUBLIC_API bool JS::CallArgs::requireAtLeast(JSContext* cx,
const char* fnname,
unsigned required) const {
if (length() < required) {
char requiredArgsStr[40];
SprintfLiteral(requiredArgsStr, "%u", required);
char actualArgsStr[40];
SprintfLiteral(actualArgsStr, "%u", length());
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
JSMSG_MORE_ARGS_NEEDED, fnname, requiredArgsStr,
required == 1 ? "" : "s", actualArgsStr);
return false;
}
return true;
JS_PUBLIC_API void JS::CallArgs::reportMoreArgsNeeded(JSContext* cx,
const char* fnname,
unsigned required,
unsigned actual) {
char requiredArgsStr[40];
SprintfLiteral(requiredArgsStr, "%u", required);
char actualArgsStr[40];
SprintfLiteral(actualArgsStr, "%u", actual);
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
JSMSG_MORE_ARGS_NEEDED, fnname, requiredArgsStr,
required == 1 ? "" : "s", actualArgsStr);
}
static bool ErrorTakesArguments(unsigned msg) {