From 1e2d2f09470a2be58a98420b4cecae731b156ee8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 11 Nov 2014 17:05:02 -0500 Subject: [dev.cc] runtime: convert memory allocator and garbage collector to Go The conversion was done with an automated tool and then modified only as necessary to make it compile and run. [This CL is part of the removal of C code from package runtime. See golang.org/s/dev.cc for an overview.] LGTM=r R=r CC=austin, dvyukov, golang-codereviews, iant, khr https://golang.org/cl/167540043 --- src/runtime/string.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/runtime/string.go') diff --git a/src/runtime/string.go b/src/runtime/string.go index 0809f89bc1..0845c94e24 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -225,7 +225,7 @@ func rawbyteslice(size int) (b []byte) { // rawruneslice allocates a new rune slice. The rune slice is not zeroed. func rawruneslice(size int) (b []rune) { - if uintptr(size) > maxmem/4 { + if uintptr(size) > _MaxMem/4 { gothrow("out of memory") } mem := goroundupsize(uintptr(size) * 4) @@ -255,9 +255,6 @@ func gostringsize(n int) string { return s } -//go:noescape -func findnull(*byte) int - func gostring(p *byte) string { l := findnull(p) if l == 0 { @@ -296,3 +293,12 @@ func contains(s, t string) bool { func hasprefix(s, t string) bool { return len(s) >= len(t) && s[:len(t)] == t } + +func goatoi(s string) int { + n := 0 + for len(s) > 0 && '0' <= s[0] && s[0] <= '9' { + n = n*10 + int(s[0]) - '0' + s = s[1:] + } + return n +} -- cgit v1.3