From 0d0c54058d61d0e9d7ead453e5f501efbacc0f92 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Sat, 11 Nov 2023 20:58:07 +0100 Subject: [PATCH] Hasten is_integer the commented further improvement should be done too imo, but up to you --- game/scripts/utility/common_functions.rpy | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/game/scripts/utility/common_functions.rpy b/game/scripts/utility/common_functions.rpy index 5096f451..dae89f72 100644 --- a/game/scripts/utility/common_functions.rpy +++ b/game/scripts/utility/common_functions.rpy @@ -130,14 +130,15 @@ init python early: return obj def is_integer(s): - def zero(s): - return (len(s) > 1 and s.startswith("0")) - s = str(s) - - if s and s[0] in ("-", "+"): - return (not zero(s[1:]) and s[1:].isdigit()) - return (not zero(s) and s.isdigit()) + if not s: + return False + if s[0] in ("-", "+"): + # calling lstrip("0+-") would be faster but not exactly identical + s = s[1:] + if s.lstrip("0").isdigit(): + return True + return False def timeit(func, loops=10000, args=(), kwargs={}): start = time.time()