OLD | NEW |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 | 6 |
7 import ( | 7 import ( |
8 "unsafe" | 8 "unsafe" |
9 ) | 9 ) |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return concatstrings(a[:]) | 54 return concatstrings(a[:]) |
55 } | 55 } |
56 | 56 |
57 //go:nosplit | 57 //go:nosplit |
58 func concatstring5(a [5]string) string { | 58 func concatstring5(a [5]string) string { |
59 return concatstrings(a[:]) | 59 return concatstrings(a[:]) |
60 } | 60 } |
61 | 61 |
62 func slicebytetostring(b []byte) string { | 62 func slicebytetostring(b []byte) string { |
63 if raceenabled && len(b) > 0 { | 63 if raceenabled && len(b) > 0 { |
64 fn := slicebytetostring | |
65 racereadrangepc(unsafe.Pointer(&b[0]), | 64 racereadrangepc(unsafe.Pointer(&b[0]), |
66 len(b), | 65 len(b), |
67 getcallerpc(unsafe.Pointer(&b)), | 66 getcallerpc(unsafe.Pointer(&b)), |
68 » » » **(**uintptr)(unsafe.Pointer(&fn))) | 67 » » » funcPC(slicebytetostring)) |
69 } | 68 } |
70 s, c := rawstring(len(b)) | 69 s, c := rawstring(len(b)) |
71 copy(c, b) | 70 copy(c, b) |
72 return s | 71 return s |
73 } | 72 } |
74 | 73 |
75 func slicebytetostringtmp(b []byte) string { | 74 func slicebytetostringtmp(b []byte) string { |
76 // Return a "string" referring to the actual []byte bytes. | 75 // Return a "string" referring to the actual []byte bytes. |
77 // This is only for use by internal compiler optimizations | 76 // This is only for use by internal compiler optimizations |
78 // that know that the string form will be discarded before | 77 // that know that the string form will be discarded before |
79 // the calling goroutine could possibly modify the original | 78 // the calling goroutine could possibly modify the original |
80 // slice or synchronize with another goroutine. | 79 // slice or synchronize with another goroutine. |
81 // Today, the only such case is a m[string(k)] lookup where | 80 // Today, the only such case is a m[string(k)] lookup where |
82 // m is a string-keyed map and k is a []byte. | 81 // m is a string-keyed map and k is a []byte. |
83 | 82 |
84 if raceenabled && len(b) > 0 { | 83 if raceenabled && len(b) > 0 { |
85 fn := slicebytetostringtmp | |
86 racereadrangepc(unsafe.Pointer(&b[0]), | 84 racereadrangepc(unsafe.Pointer(&b[0]), |
87 len(b), | 85 len(b), |
88 getcallerpc(unsafe.Pointer(&b)), | 86 getcallerpc(unsafe.Pointer(&b)), |
89 » » » **(**uintptr)(unsafe.Pointer(&fn))) | 87 » » » funcPC(slicebytetostringtmp)) |
90 } | 88 } |
91 return *(*string)(unsafe.Pointer(&b)) | 89 return *(*string)(unsafe.Pointer(&b)) |
92 } | 90 } |
93 | 91 |
94 func stringtoslicebyte(s string) []byte { | 92 func stringtoslicebyte(s string) []byte { |
95 b := rawbyteslice(len(s)) | 93 b := rawbyteslice(len(s)) |
96 copy(b, s) | 94 copy(b, s) |
97 return b | 95 return b |
98 } | 96 } |
99 | 97 |
(...skipping 13 matching lines...) Expand all Loading... |
113 r, k := charntorune(t) | 111 r, k := charntorune(t) |
114 t = t[k:] | 112 t = t[k:] |
115 a[n] = r | 113 a[n] = r |
116 n++ | 114 n++ |
117 } | 115 } |
118 return a | 116 return a |
119 } | 117 } |
120 | 118 |
121 func slicerunetostring(a []rune) string { | 119 func slicerunetostring(a []rune) string { |
122 if raceenabled && len(a) > 0 { | 120 if raceenabled && len(a) > 0 { |
123 fn := slicerunetostring | |
124 racereadrangepc(unsafe.Pointer(&a[0]), | 121 racereadrangepc(unsafe.Pointer(&a[0]), |
125 len(a)*int(unsafe.Sizeof(a[0])), | 122 len(a)*int(unsafe.Sizeof(a[0])), |
126 getcallerpc(unsafe.Pointer(&a)), | 123 getcallerpc(unsafe.Pointer(&a)), |
127 » » » **(**uintptr)(unsafe.Pointer(&fn))) | 124 » » » funcPC(slicerunetostring)) |
128 } | 125 } |
129 var dum [4]byte | 126 var dum [4]byte |
130 size1 := 0 | 127 size1 := 0 |
131 for _, r := range a { | 128 for _, r := range a { |
132 size1 += runetochar(dum[:], r) | 129 size1 += runetochar(dum[:], r) |
133 } | 130 } |
134 s, b := rawstring(size1 + 3) | 131 s, b := rawstring(size1 + 3) |
135 size2 := 0 | 132 size2 := 0 |
136 for _, r := range a { | 133 for _, r := range a { |
137 // check for race | 134 // check for race |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 p := gomallocgc(mem, nil, flagNoScan|flagNoZero) | 245 p := gomallocgc(mem, nil, flagNoScan|flagNoZero) |
249 if mem != uintptr(size)*4 { | 246 if mem != uintptr(size)*4 { |
250 memclr(add(p, uintptr(size)*4), mem-uintptr(size)*4) | 247 memclr(add(p, uintptr(size)*4), mem-uintptr(size)*4) |
251 } | 248 } |
252 | 249 |
253 (*slice)(unsafe.Pointer(&b)).array = (*uint8)(p) | 250 (*slice)(unsafe.Pointer(&b)).array = (*uint8)(p) |
254 (*slice)(unsafe.Pointer(&b)).len = uint(size) | 251 (*slice)(unsafe.Pointer(&b)).len = uint(size) |
255 (*slice)(unsafe.Pointer(&b)).cap = uint(mem / 4) | 252 (*slice)(unsafe.Pointer(&b)).cap = uint(mem / 4) |
256 return | 253 return |
257 } | 254 } |
OLD | NEW |