diff options
Diffstat (limited to 'src/pkg/runtime/string.goc')
-rw-r--r-- | src/pkg/runtime/string.goc | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index 49bf1148b..b79acbe1c 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -7,13 +7,15 @@ package runtime #include "arch_GOARCH.h" #include "malloc.h" #include "race.h" +#include "../../cmd/ld/textflag.h" String runtime·emptystring; -int32 +#pragma textflag NOSPLIT +intgo runtime·findnull(byte *s) { - int32 l; + intgo l; if(s == nil) return 0; @@ -22,10 +24,10 @@ runtime·findnull(byte *s) return l; } -int32 +intgo runtime·findnullw(uint16 *s) { - int32 l; + intgo l; if(s == nil) return 0; @@ -34,23 +36,23 @@ runtime·findnullw(uint16 *s) return l; } -uint32 runtime·maxstring = 256; // a hint for print +uintptr runtime·maxstring = 256; // a hint for print static String gostringsize(intgo l) { String s; - uint32 ms; + uintptr ms; if(l == 0) return runtime·emptystring; // leave room for NUL for C runtime (e.g., callers of getenv) - s.str = runtime·mallocgc(l+1, FlagNoPointers, 1, 0); + s.str = runtime·mallocgc(l+1, 0, FlagNoScan|FlagNoZero); s.len = l; s.str[l] = 0; for(;;) { ms = runtime·maxstring; - if((uint32)l <= ms || runtime·cas(&runtime·maxstring, ms, (uint32)l)) + if((uintptr)l <= ms || runtime·casp((void**)&runtime·maxstring, (void*)ms, (void*)l)) break; } return s; @@ -83,7 +85,7 @@ runtime·gobytes(byte *p, intgo n) { Slice sl; - sl.array = runtime·mallocgc(n, FlagNoPointers, 1, 0); + sl.array = runtime·mallocgc(n, 0, FlagNoScan|FlagNoZero); sl.len = n; sl.cap = n; runtime·memmove(sl.array, p, n); @@ -100,6 +102,13 @@ runtime·gostringnocopy(byte *str) return s; } +void +runtime·cstringToGo(byte *str, String s) +{ + s = runtime·gostringnocopy(str); + FLUSH(&s); +} + String runtime·gostringw(uint16 *str) { @@ -170,39 +179,14 @@ concatstring(intgo n, String *s) return out; } -#pragma textflag 7 -// s1 is the first of n strings. -// the output string follows. -func concatstring(n int, s1 String) { - (&s1)[n] = concatstring(n, &s1); -} - -static int32 -cmpstring(String s1, String s2) +// NOTE: Cannot use func syntax, because we need the ..., +// to signal to the garbage collector that this function does +// not have a fixed size argument count. +#pragma textflag NOSPLIT +void +runtime·concatstring(intgo n, String s1, ...) { - uintgo i, l; - byte c1, c2; - - l = s1.len; - if(s2.len < l) - l = s2.len; - for(i=0; i<l; i++) { - c1 = s1.str[i]; - c2 = s2.str[i]; - if(c1 < c2) - return -1; - if(c1 > c2) - return +1; - } - if(s1.len < s2.len) - return -1; - if(s1.len > s2.len) - return +1; - return 0; -} - -func cmpstring(s1 String, s2 String) (v int) { - v = cmpstring(s1, s2); + (&s1)[n] = concatstring(n, &s1); } func eqstring(s1 String, s2 String) (v bool) { @@ -268,14 +252,14 @@ func slicebytetostring(b Slice) (s String) { if(raceenabled) { pc = runtime·getcallerpc(&b); - runtime·racereadrangepc(b.array, b.len, 1, pc, runtime·slicebytetostring); + runtime·racereadrangepc(b.array, b.len, pc, runtime·slicebytetostring); } s = gostringsize(b.len); runtime·memmove(s.str, b.array, s.len); } func stringtoslicebyte(s String) (b Slice) { - b.array = runtime·mallocgc(s.len, FlagNoPointers, 1, 0); + b.array = runtime·mallocgc(s.len, 0, FlagNoScan|FlagNoZero); b.len = s.len; b.cap = s.len; runtime·memmove(b.array, s.str, s.len); @@ -289,7 +273,7 @@ func slicerunetostring(b Slice) (s String) { if(raceenabled) { pc = runtime·getcallerpc(&b); - runtime·racereadrangepc(b.array, b.len*sizeof(*a), sizeof(*a), pc, runtime·slicerunetostring); + runtime·racereadrangepc(b.array, b.len*sizeof(*a), pc, runtime·slicerunetostring); } a = (int32*)b.array; siz1 = 0; @@ -324,7 +308,7 @@ func stringtoslicerune(s String) (b Slice) { n++; } - b.array = runtime·mallocgc(n*sizeof(r[0]), FlagNoPointers, 1, 0); + b.array = runtime·mallocgc(n*sizeof(r[0]), 0, FlagNoScan|FlagNoZero); b.len = n; b.cap = n; p = s.str; |