Skip to content

Commit 92bee04

Browse files
committed
reuse Caml_int64.to_string
1 parent 040ba95 commit 92bee04

File tree

3 files changed

+5
-38
lines changed

3 files changed

+5
-38
lines changed

jscomp/runtime/caml_format.ml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,20 +398,11 @@ let dec_of_pos_int64 x =
398398
let c, d = Caml_int64.div_mod y wbase in
399399
let e ,f = Caml_int64.div_mod (Caml_int64_extern.add modulus_l d) wbase in
400400
let quotient =
401-
ref (Caml_int64_extern.add (Caml_int64_extern.add quotient_l c )
401+
(Caml_int64_extern.add (Caml_int64_extern.add quotient_l c )
402402
e) in
403-
let modulus = ref f in
404-
let s = ref
403+
Caml_int64.to_string quotient ^
405404
(Caml_string_extern.get_string_unsafe
406-
cvtbl (Caml_int64_extern.to_int modulus.contents)) in
407-
408-
while quotient.contents <> 0L do
409-
let a, b = Caml_int64.div_mod (quotient.contents) wbase in
410-
quotient .contents<- a;
411-
modulus .contents<- b;
412-
s .contents<- Caml_string_extern.get_string_unsafe cvtbl (Caml_int64_extern.to_int modulus.contents) ^ s.contents ;
413-
done;
414-
s.contents
405+
cvtbl (Caml_int64_extern.to_int f))
415406
else
416407
Caml_int64.to_string x)
417408

lib/es6/caml_format.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ function dec_of_pos_int64(x) {
585585
/* hi */0,
586586
/* lo */10
587587
];
588-
var cvtbl = "0123456789";
589588
var y = Caml_int64.discard_sign(x);
590589
var match = Caml_int64.div_mod(y, wbase);
591590
var match$1 = Caml_int64.div_mod(Caml_int64.add(/* int64 */[
@@ -596,18 +595,7 @@ function dec_of_pos_int64(x) {
596595
/* hi */214748364,
597596
/* lo */3435973836
598597
], match[0]), match$1[0]);
599-
var modulus = match$1[1];
600-
var s = cvtbl[Caml_int64.to_int32(modulus)];
601-
while(Caml_int64.neq(quotient, /* int64 */[
602-
/* hi */0,
603-
/* lo */0
604-
])) {
605-
var match$2 = Caml_int64.div_mod(quotient, wbase);
606-
quotient = match$2[0];
607-
modulus = match$2[1];
608-
s = cvtbl[Caml_int64.to_int32(modulus)] + s;
609-
};
610-
return s;
598+
return Caml_int64.to_string(quotient) + "0123456789"[Caml_int64.to_int32(match$1[1])];
611599
} else {
612600
return Caml_int64.to_string(x);
613601
}

lib/js/caml_format.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ function dec_of_pos_int64(x) {
585585
/* hi */0,
586586
/* lo */10
587587
];
588-
var cvtbl = "0123456789";
589588
var y = Caml_int64.discard_sign(x);
590589
var match = Caml_int64.div_mod(y, wbase);
591590
var match$1 = Caml_int64.div_mod(Caml_int64.add(/* int64 */[
@@ -596,18 +595,7 @@ function dec_of_pos_int64(x) {
596595
/* hi */214748364,
597596
/* lo */3435973836
598597
], match[0]), match$1[0]);
599-
var modulus = match$1[1];
600-
var s = cvtbl[Caml_int64.to_int32(modulus)];
601-
while(Caml_int64.neq(quotient, /* int64 */[
602-
/* hi */0,
603-
/* lo */0
604-
])) {
605-
var match$2 = Caml_int64.div_mod(quotient, wbase);
606-
quotient = match$2[0];
607-
modulus = match$2[1];
608-
s = cvtbl[Caml_int64.to_int32(modulus)] + s;
609-
};
610-
return s;
598+
return Caml_int64.to_string(quotient) + "0123456789"[Caml_int64.to_int32(match$1[1])];
611599
} else {
612600
return Caml_int64.to_string(x);
613601
}

0 commit comments

Comments
 (0)