runtime·gostringnocopy(byte *str)
{
String s;
+ uintptr ms;
s.str = str;
s.len = runtime·findnull(str);
- return s;
+ while(true) {
+ ms = runtime·maxstring;
+ if(s.len <= ms || runtime·casp((void**)&runtime·maxstring, (void*)ms, (void*)s.len))
+ return s;
+ }
}
// TODO: move this elsewhere
panic(s)
}
`
+
+func TestGostringnocopy(t *testing.T) {
+ max := *runtime.Maxstring
+ b := make([]byte, max+10)
+ for i := uintptr(0); i < max+9; i++ {
+ b[i] = 'a'
+ }
+ _ = runtime.Gostringnocopy(&b[0])
+ newmax := *runtime.Maxstring
+ if newmax != max+9 {
+ t.Errorf("want %d, got %d", max+9, newmax)
+ }
+}