LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 #include "runtime.h" | 6 #include "runtime.h" |
7 #include "arch_GOARCH.h" | 7 #include "arch_GOARCH.h" |
8 #include "malloc.h" | 8 #include "malloc.h" |
9 #include "race.h" | 9 #include "race.h" |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 static String | 39 static String |
40 gostringsize(intgo l) | 40 gostringsize(intgo l) |
41 { | 41 { |
42 String s; | 42 String s; |
43 uint32 ms; | 43 uint32 ms; |
44 | 44 |
45 if(l == 0) | 45 if(l == 0) |
46 return runtime·emptystring; | 46 return runtime·emptystring; |
47 // leave room for NUL for C runtime (e.g., callers of getenv) | 47 // leave room for NUL for C runtime (e.g., callers of getenv) |
48 » s.str = runtime·mallocgc(l+1, FlagNoPointers, 1, 0); | 48 » s.str = runtime·mallocgc(l+1, 0, FlagNoPointers|FlagNoZero); |
49 s.len = l; | 49 s.len = l; |
50 s.str[l] = 0; | 50 s.str[l] = 0; |
51 for(;;) { | 51 for(;;) { |
52 ms = runtime·maxstring; | 52 ms = runtime·maxstring; |
53 if((uint32)l <= ms || runtime·cas(&runtime·maxstring, ms, (uint3
2)l)) | 53 if((uint32)l <= ms || runtime·cas(&runtime·maxstring, ms, (uint3
2)l)) |
54 break; | 54 break; |
55 } | 55 } |
56 return s; | 56 return s; |
57 } | 57 } |
58 | 58 |
(...skipping 17 matching lines...) Expand all Loading... |
76 s = gostringsize(l); | 76 s = gostringsize(l); |
77 runtime·memmove(s.str, str, l); | 77 runtime·memmove(s.str, str, l); |
78 return s; | 78 return s; |
79 } | 79 } |
80 | 80 |
81 Slice | 81 Slice |
82 runtime·gobytes(byte *p, intgo n) | 82 runtime·gobytes(byte *p, intgo n) |
83 { | 83 { |
84 Slice sl; | 84 Slice sl; |
85 | 85 |
86 » sl.array = runtime·mallocgc(n, FlagNoPointers, 1, 0); | 86 » sl.array = runtime·mallocgc(n, 0, FlagNoPointers|FlagNoZero); |
87 sl.len = n; | 87 sl.len = n; |
88 sl.cap = n; | 88 sl.cap = n; |
89 runtime·memmove(sl.array, p, n); | 89 runtime·memmove(sl.array, p, n); |
90 return sl; | 90 return sl; |
91 } | 91 } |
92 | 92 |
93 String | 93 String |
94 runtime·gostringnocopy(byte *str) | 94 runtime·gostringnocopy(byte *str) |
95 { | 95 { |
96 String s; | 96 String s; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 if(raceenabled) { | 244 if(raceenabled) { |
245 pc = runtime·getcallerpc(&b); | 245 pc = runtime·getcallerpc(&b); |
246 runtime·racereadrangepc(b.array, b.len, pc, runtime·slicebytetos
tring); | 246 runtime·racereadrangepc(b.array, b.len, pc, runtime·slicebytetos
tring); |
247 } | 247 } |
248 s = gostringsize(b.len); | 248 s = gostringsize(b.len); |
249 runtime·memmove(s.str, b.array, s.len); | 249 runtime·memmove(s.str, b.array, s.len); |
250 } | 250 } |
251 | 251 |
252 func stringtoslicebyte(s String) (b Slice) { | 252 func stringtoslicebyte(s String) (b Slice) { |
253 » b.array = runtime·mallocgc(s.len, FlagNoPointers, 1, 0); | 253 » b.array = runtime·mallocgc(s.len, 0, FlagNoPointers|FlagNoZero); |
254 b.len = s.len; | 254 b.len = s.len; |
255 b.cap = s.len; | 255 b.cap = s.len; |
256 runtime·memmove(b.array, s.str, s.len); | 256 runtime·memmove(b.array, s.str, s.len); |
257 } | 257 } |
258 | 258 |
259 func slicerunetostring(b Slice) (s String) { | 259 func slicerunetostring(b Slice) (s String) { |
260 intgo siz1, siz2, i; | 260 intgo siz1, siz2, i; |
261 int32 *a; | 261 int32 *a; |
262 byte dum[8]; | 262 byte dum[8]; |
263 void *pc; | 263 void *pc; |
(...skipping 28 matching lines...) Expand all Loading... |
292 // two passes. | 292 // two passes. |
293 // unlike slicerunetostring, no race because strings are immutable. | 293 // unlike slicerunetostring, no race because strings are immutable. |
294 p = s.str; | 294 p = s.str; |
295 ep = s.str+s.len; | 295 ep = s.str+s.len; |
296 n = 0; | 296 n = 0; |
297 while(p < ep) { | 297 while(p < ep) { |
298 p += runtime·charntorune(&dum, p, ep-p); | 298 p += runtime·charntorune(&dum, p, ep-p); |
299 n++; | 299 n++; |
300 } | 300 } |
301 | 301 |
302 » b.array = runtime·mallocgc(n*sizeof(r[0]), FlagNoPointers, 1, 0); | 302 » b.array = runtime·mallocgc(n*sizeof(r[0]), 0, FlagNoPointers|FlagNoZero)
; |
303 b.len = n; | 303 b.len = n; |
304 b.cap = n; | 304 b.cap = n; |
305 p = s.str; | 305 p = s.str; |
306 r = (int32*)b.array; | 306 r = (int32*)b.array; |
307 while(p < ep) | 307 while(p < ep) |
308 p += runtime·charntorune(r++, p, ep-p); | 308 p += runtime·charntorune(r++, p, ep-p); |
309 } | 309 } |
310 | 310 |
311 enum | 311 enum |
312 { | 312 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if(retv < Runeself) { | 346 if(retv < Runeself) { |
347 retk = k+1; | 347 retk = k+1; |
348 goto out; | 348 goto out; |
349 } | 349 } |
350 | 350 |
351 // multi-char rune | 351 // multi-char rune |
352 retk = k + runtime·charntorune(&retv, s.str+k, s.len-k); | 352 retk = k + runtime·charntorune(&retv, s.str+k, s.len-k); |
353 | 353 |
354 out: | 354 out: |
355 } | 355 } |
LEFT | RIGHT |