Skip to content

Commit 8a33c3c

Browse files
committed
Simplify caml_str_repeat
1 parent 3a5ef2a commit 8a33c3c

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

runtime/js/ieee_754.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function caml_fma_float(x, y, z) {
434434
}
435435

436436
//Provides: caml_format_float const
437-
//Requires: caml_parse_format, caml_finish_formatting
437+
//Requires: caml_str_repeat, caml_parse_format, caml_finish_formatting
438438
function caml_format_float(fmt, x) {
439439
function toFixed(x, dp) {
440440
if (Math.abs(x) < 1.0) {
@@ -444,9 +444,9 @@ function caml_format_float(fmt, x) {
444444
if (e > 20) {
445445
e -= 20;
446446
x /= Math.pow(10, e);
447-
x += new Array(e + 1).join("0");
447+
x += caml_str_repeat(e,"0");
448448
if (dp > 0) {
449-
x = x + "." + new Array(dp + 1).join("0");
449+
x = x + "." + caml_str_repeat(dp,"0");
450450
}
451451
return x;
452452
} else return x.toFixed(dp);

runtime/js/mlBytes.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,7 @@
4747
// kind(x) = x&6
4848

4949
//Provides: caml_str_repeat
50-
function caml_str_repeat(n, s) {
51-
if (n === 0) return "";
52-
if (s.repeat) {
53-
return s.repeat(n);
54-
} // ECMAscript 6 and Firefox 24+
55-
var r = "",
56-
l = 0;
57-
for (;;) {
58-
if (n & 1) r += s;
59-
n >>= 1;
60-
if (n === 0) return r;
61-
s += s;
62-
l++;
63-
if (l === 9) {
64-
s.slice(0, 1); // flatten the string
65-
// then, the flattening of the whole string will be faster,
66-
// as it will be composed of larger pieces
67-
}
68-
}
69-
}
50+
function caml_str_repeat(n, s) { return s.repeat(n); }
7051

7152
//Provides: caml_subarray_to_jsbytes
7253
//Weakdef

0 commit comments

Comments
 (0)