diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/runtime/string.goc | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/runtime/string.goc')
-rw-r--r-- | src/pkg/runtime/string.goc | 98 |
1 files changed, 57 insertions, 41 deletions
diff --git a/src/pkg/runtime/string.goc b/src/pkg/runtime/string.goc index 7e1f8a1e8..c0d3f2bde 100644 --- a/src/pkg/runtime/string.goc +++ b/src/pkg/runtime/string.goc @@ -6,6 +6,7 @@ package runtime #include "runtime.h" #include "arch_GOARCH.h" #include "malloc.h" +#include "race.h" String runtime·emptystring; @@ -33,10 +34,10 @@ runtime·findnullw(uint16 *s) return l; } -uint32 runtime·maxstring = 256; +uint32 runtime·maxstring = 256; // a hint for print static String -gostringsize(int32 l) +gostringsize(intgo l) { String s; uint32 ms; @@ -58,7 +59,7 @@ gostringsize(int32 l) String runtime·gostring(byte *str) { - int32 l; + intgo l; String s; l = runtime·findnull(str); @@ -68,7 +69,7 @@ runtime·gostring(byte *str) } String -runtime·gostringn(byte *str, int32 l) +runtime·gostringn(byte *str, intgo l) { String s; @@ -78,7 +79,7 @@ runtime·gostringn(byte *str, int32 l) } Slice -runtime·gobytes(byte *p, int32 n) +runtime·gobytes(byte *p, intgo n) { Slice sl; @@ -102,7 +103,7 @@ runtime·gostringnocopy(byte *str) String runtime·gostringw(uint16 *str) { - int32 n1, n2, i; + intgo n1, n2, i; byte buf[8]; String s; @@ -139,17 +140,26 @@ runtime·catstring(String s1, String s2) } static String -concatstring(int32 n, String *s) +concatstring(intgo n, String *s) { - int32 i, l; + intgo i, l, count; String out; l = 0; + count = 0; for(i=0; i<n; i++) { if(l + s[i].len < l) runtime·throw("string concatenation too long"); l += s[i].len; + if(s[i].len > 0) { + count++; + out = s[i]; + } } + if(count == 0) + return runtime·emptystring; + if(count == 1) // zero or one non-empty string in concatenation + return out; out = gostringsize(l); l = 0; @@ -163,14 +173,14 @@ concatstring(int32 n, String *s) #pragma textflag 7 // s1 is the first of n strings. // the output string follows. -func concatstring(n int32, s1 String) { +func concatstring(n int, s1 String) { (&s1)[n] = concatstring(n, &s1); } static int32 cmpstring(String s1, String s2) { - uint32 i, l; + uintgo i, l; byte c1, c2; l = s1.len; @@ -191,14 +201,34 @@ cmpstring(String s1, String s2) return 0; } -func cmpstring(s1 String, s2 String) (v int32) { +func cmpstring(s1 String, s2 String) (v int) { v = cmpstring(s1, s2); } +func eqstring(s1 String, s2 String) (v bool) { + uintgo i, l; + + if(s1.len != s2.len) { + v = false; + return; + } + if(s1.str == s2.str) { + v = true; + return; + } + l = s1.len; + for(i=0; i<l; i++) + if(s1.str[i] != s2.str[i]) { + v = false; + return; + } + v = true; +} + int32 runtime·strcmp(byte *s1, byte *s2) { - uint32 i; + uintptr i; byte c1, c2; for(i=0;; i++) { @@ -235,31 +265,6 @@ runtime·strstr(byte *s1, byte *s2) return nil; } -func slicestring(si String, lindex int32, hindex int32) (so String) { - int32 l; - - if(lindex < 0 || lindex > si.len || - hindex < lindex || hindex > si.len) { - runtime·panicslice(); - } - - l = hindex-lindex; - so.str = si.str + lindex; - so.len = l; -} - -func slicestring1(si String, lindex int32) (so String) { - int32 l; - - if(lindex < 0 || lindex > si.len) { - runtime·panicslice(); - } - - l = si.len-lindex; - so.str = si.str + lindex; - so.len = l; -} - func intstring(v int64) (s String) { s = gostringsize(8); s.len = runtime·runetochar(s.str, v); @@ -267,6 +272,12 @@ func intstring(v int64) (s String) { } func slicebytetostring(b Slice) (s String) { + void *pc; + + if(raceenabled) { + pc = runtime·getcallerpc(&b); + runtime·racereadrangepc(b.array, b.len, 1, pc, runtime·slicebytetostring); + } s = gostringsize(b.len); runtime·memmove(s.str, b.array, s.len); } @@ -279,10 +290,15 @@ func stringtoslicebyte(s String) (b Slice) { } func slicerunetostring(b Slice) (s String) { - int32 siz1, siz2, i; + intgo siz1, siz2, i; int32 *a; byte dum[8]; + void *pc; + if(raceenabled) { + pc = runtime·getcallerpc(&b); + runtime·racereadrangepc(b.array, b.len*sizeof(*a), sizeof(*a), pc, runtime·slicerunetostring); + } a = (int32*)b.array; siz1 = 0; for(i=0; i<b.len; i++) { @@ -302,7 +318,7 @@ func slicerunetostring(b Slice) (s String) { } func stringtoslicerune(s String) (b Slice) { - int32 n; + intgo n; int32 dum, *r; uint8 *p, *ep; @@ -330,7 +346,7 @@ enum Runeself = 0x80, }; -func stringiter(s String, k int32) (retk int32) { +func stringiter(s String, k int) (retk int) { int32 l; if(k >= s.len) { @@ -351,7 +367,7 @@ func stringiter(s String, k int32) (retk int32) { out: } -func stringiter2(s String, k int32) (retk int32, retv int32) { +func stringiter2(s String, k int) (retk int, retv int32) { if(k >= s.len) { // retk=0 is end of iteration retk = 0; |