forked from SilverStudioGames/WTS
Hasten is_integer
the commented further improvement should be done too imo, but up to you
This commit is contained in:
parent
18f3ae4219
commit
b6d07aaa99
@ -127,14 +127,15 @@ init python early:
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
def is_integer(s):
|
def is_integer(s):
|
||||||
def zero(s):
|
|
||||||
return (len(s) > 1 and s.startswith("0"))
|
|
||||||
|
|
||||||
s = str(s)
|
s = str(s)
|
||||||
|
if not s:
|
||||||
if s and s[0] in ("-", "+"):
|
return False
|
||||||
return (not zero(s[1:]) and s[1:].isdigit())
|
if s[0] in ("-", "+"):
|
||||||
return (not zero(s) and s.isdigit())
|
# 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={}):
|
def timeit(func, loops=10000, args=(), kwargs={}):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
Loading…
Reference in New Issue
Block a user