Skip to content

Commit 2c7814d

Browse files
committed
Simplify caml_str_repeat
1 parent 02f1bf3 commit 2c7814d

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

runtime/js/ieee_754.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function caml_fma_float(x, y, z) {
423423
}
424424

425425
//Provides: caml_format_float const
426-
//Requires: caml_parse_format, caml_finish_formatting
426+
//Requires: caml_str_repeat, caml_parse_format, caml_finish_formatting
427427
function caml_format_float(fmt, x) {
428428
function toFixed(x, dp) {
429429
if (Math.abs(x) < 1.0) {
@@ -433,9 +433,9 @@ function caml_format_float(fmt, x) {
433433
if (e > 20) {
434434
e -= 20;
435435
x /= Math.pow(10, e);
436-
x += new Array(e + 1).join("0");
436+
x += caml_str_repeat(e, "0");
437437
if (dp > 0) {
438-
x = x + "." + new Array(dp + 1).join("0");
438+
x = x + "." + caml_str_repeat(dp, "0");
439439
}
440440
return x;
441441
} else return x.toFixed(dp);

runtime/js/mlBytes.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,7 @@
4848

4949
//Provides: caml_str_repeat
5050
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-
}
51+
return s.repeat(n);
6952
}
7053

7154
//Provides: caml_subarray_to_jsbytes

0 commit comments

Comments
 (0)