mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string: faster int()
This commit is contained in:
@ -176,9 +176,29 @@ pub fn (s string) replace(rep, with string) string {
|
||||
return tos(b, new_len)
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn (s string) int() int {
|
||||
return strconv.parse_int(s, 0, 32)
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn (s string) int() int {
|
||||
mut neg := false
|
||||
mut i := 0
|
||||
if s[0] == `-` {
|
||||
neg = true
|
||||
i++
|
||||
}
|
||||
else if s[0] == `+` {
|
||||
i++
|
||||
}
|
||||
mut n := 0
|
||||
for C.isdigit(s[i]) {
|
||||
n = 10 * n - int(s[i] - `0`)
|
||||
i++
|
||||
}
|
||||
return if neg { n } else { -n }
|
||||
}
|
||||
|
||||
|
||||
pub fn (s string) i64() i64 {
|
||||
|
Reference in New Issue
Block a user