From 7b2250a7e60968b0c3716a7caa780e6ca0a2ce9b Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Tue, 16 May 2017 13:15:41 +1000 Subject: [PATCH] optimisation: when converting to double, may not need stringrep Minor optimisation Signed-off-by: Steve Bennett --- jim.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/jim.c b/jim.c index 18217b7..9e2bb81 100644 --- a/jim.c +++ b/jim.c @@ -6013,11 +6013,6 @@ static int SetDoubleFromAny(Jim_Interp *interp, Jim_Obj *objPtr) jim_wide wideValue; const char *str; - /* Preserve the string representation. - * Needed so we can convert back to int without loss - */ - str = Jim_String(objPtr); - #ifdef HAVE_LONG_LONG /* Assume a 53 bit mantissa */ #define MIN_INT_IN_DOUBLE -(1LL << 53) @@ -6031,8 +6026,12 @@ static int SetDoubleFromAny(Jim_Interp *interp, Jim_Obj *objPtr) objPtr->typePtr = &coercedDoubleObjType; return JIM_OK; } - else #endif + /* Preserve the string representation. + * Needed so we can convert back to int without loss + */ + str = Jim_String(objPtr); + if (Jim_StringToWide(str, &wideValue, 10) == JIM_OK) { /* Managed to convert to an int, so we can use this as a cooerced double */ Jim_FreeIntRep(interp, objPtr); -- 2.11.4.GIT