mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: make gostringnocopy update maxstring
Fixes #8706 LGTM=josharian R=josharian CC=golang-codereviews https://golang.org/cl/143880043
This commit is contained in:
parent
6e55f7a87b
commit
bcd36e8857
3 changed files with 22 additions and 1 deletions
|
|
@ -160,3 +160,6 @@ func GostringW(w []uint16) (s string) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Gostringnocopy = gostringnocopy
|
||||||
|
var Maxstring = &maxstring
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,15 @@ String
|
||||||
runtime·gostringnocopy(byte *str)
|
runtime·gostringnocopy(byte *str)
|
||||||
{
|
{
|
||||||
String s;
|
String s;
|
||||||
|
uintptr ms;
|
||||||
|
|
||||||
s.str = str;
|
s.str = str;
|
||||||
s.len = runtime·findnull(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
|
// TODO: move this elsewhere
|
||||||
|
|
|
||||||
|
|
@ -145,3 +145,16 @@ func main() {
|
||||||
panic(s)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue