nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
lib/string: `Int::to_s` shortcuts 0 and 1
[nit.git]
/
lib
/
standard
/
string.nit
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'