1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibJS: Cache the number format used for compact notation

Finding the best number format to use for compact notation involves
creating a Vector of all compact formats for the locale and looking for
the one that best matches the number's magnitude. ECMA-402 wants this
number format to be found multiple times, so cache the result for future
use.
This commit is contained in:
Timothy Flynn 2021-11-15 08:26:55 -05:00 committed by Linus Groh
parent 1f546476d5
commit 80b86d20dc
2 changed files with 13 additions and 2 deletions

View file

@ -11,7 +11,6 @@
#include <LibJS/Runtime/Intl/NumberFormat.h>
#include <LibJS/Runtime/Intl/NumberFormatFunction.h>
#include <LibUnicode/CurrencyCode.h>
#include <LibUnicode/Locale.h>
#include <math.h>
#include <stdlib.h>
@ -1599,7 +1598,11 @@ int compute_exponent_for_magniude(NumberFormat& number_format, int magnitude)
best_number_format = &format_rule;
}
return best_number_format ? best_number_format->exponent : 0;
if (best_number_format == nullptr)
return 0;
number_format.set_compact_format(*best_number_format);
return best_number_format->exponent;
}
default: