nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
02bd2e5
)
lib/string: `Int::to_s` shortcuts 0 and 1
author
Jean Privat
<jean@pryen.org>
Mon, 16 Mar 2015 02:10:27 +0000
(09:10 +0700)
committer
Jean Privat
<jean@pryen.org>
Mon, 16 Mar 2015 02:10:27 +0000
(09:10 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>
lib/standard/string.nit
patch
|
blob
|
history
diff --git
a/lib/standard/string.nit
b/lib/standard/string.nit
index
e78f655
..
63c8226
100644
(file)
--- a/
lib/standard/string.nit
+++ b/
lib/standard/string.nit
@@
-1953,6
+1953,10
@@
redef class Int
# assert 1.to_s == "1"
# assert (-123).to_s == "-123"
redef fun to_s do
+ # Fast case for common numbers
+ if self == 0 then return "0"
+ if self == 1 then return "1"
+
var nslen = int_to_s_len
var ns = new NativeString(nslen + 1)
ns[nslen] = '\0'