Example #1
0
static void 
growslice1 ( SliceType *t , Slice x , intgo newcap , Slice *ret ) 
{ 
intgo newcap1; 
uintptr capmem , lenmem; 
int32 flag; 
Type *typ; 
#line 94 "/home/pi/go_build/hg/go/src/pkg/runtime/slice.goc"
typ = t->elem; 
if ( typ->size == 0 ) { 
*ret = x; 
ret->cap = newcap; 
return; 
} 
#line 101 "/home/pi/go_build/hg/go/src/pkg/runtime/slice.goc"
newcap1 = x.cap; 
#line 107 "/home/pi/go_build/hg/go/src/pkg/runtime/slice.goc"
if ( newcap1+newcap1 < newcap ) 
newcap1 = newcap; 
else { 
do { 
if ( x.len < 1024 ) 
newcap1 += newcap1; 
else 
newcap1 += newcap1/4; 
} while ( newcap1 < newcap ) ; 
} 
#line 118 "/home/pi/go_build/hg/go/src/pkg/runtime/slice.goc"
if ( newcap1 > MaxMem/typ->size ) 
runtime·panicstring ( "growslice: cap out of range" ) ; 
capmem = runtime·roundupsize ( newcap1*typ->size ) ; 
flag = FlagNoZero; 
if ( typ->kind&KindNoPointers ) 
flag |= FlagNoScan; 
#line 126 "/home/pi/go_build/hg/go/src/pkg/runtime/slice.goc"
m->locks++; 
ret->array = runtime·mallocgc ( capmem , ( uintptr ) typ|TypeInfo_Array , flag ) ; 
ret->len = x.len; 
ret->cap = capmem/typ->size; 
lenmem = x.len*typ->size; 
runtime·memmove ( ret->array , x.array , lenmem ) ; 
runtime·memclr ( ret->array+lenmem , capmem-lenmem ) ; 
m->locks--; 
if ( m->locks == 0 && g->preempt ) 
g->stackguard0 = StackPreempt; 
} 
Example #2
0
static void 
growslice1 ( SliceType *t , Slice x , intgo newcap , Slice *ret ) 
{ 
intgo newcap1; 
uintptr capmem , lenmem; 
int32 flag; 
Type *typ; 
#line 94 "C:\Users\ADMINI~1\AppData\Local\Temp\2\makerelease686069423\go\src\pkg\runtime\slice.goc"
typ = t->elem; 
if ( typ->size == 0 ) { 
*ret = x; 
ret->cap = newcap; 
return; 
} 
#line 101 "C:\Users\ADMINI~1\AppData\Local\Temp\2\makerelease686069423\go\src\pkg\runtime\slice.goc"
newcap1 = x.cap; 
#line 107 "C:\Users\ADMINI~1\AppData\Local\Temp\2\makerelease686069423\go\src\pkg\runtime\slice.goc"
if ( newcap1+newcap1 < newcap ) 
newcap1 = newcap; 
else { 
do { 
if ( x.len < 1024 ) 
newcap1 += newcap1; 
else 
newcap1 += newcap1/4; 
} while ( newcap1 < newcap ) ; 
} 
#line 118 "C:\Users\ADMINI~1\AppData\Local\Temp\2\makerelease686069423\go\src\pkg\runtime\slice.goc"
if ( newcap1 > MaxMem/typ->size ) 
runtime·panicstring ( "growslice: cap out of range" ) ; 
capmem = runtime·roundupsize ( newcap1*typ->size ) ; 
flag = 0; 
#line 123 "C:\Users\ADMINI~1\AppData\Local\Temp\2\makerelease686069423\go\src\pkg\runtime\slice.goc"
if ( typ->kind&KindNoPointers ) 
flag = FlagNoScan|FlagNoZero; 
ret->array = runtime·mallocgc ( capmem , ( uintptr ) typ|TypeInfo_Array , flag ) ; 
ret->len = x.len; 
ret->cap = capmem/typ->size; 
lenmem = x.len*typ->size; 
runtime·memmove ( ret->array , x.array , lenmem ) ; 
if ( typ->kind&KindNoPointers ) 
runtime·memclr ( ret->array+lenmem , capmem-lenmem ) ; 
} 
Example #3
0
void
runtime·stringtoslicebyte(String s, Slice b)
{
	b.array = 0;
	b.len = 0;
	b.cap = 0;
	FLUSH(&b);
#line 297 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc"

	uintptr cap;

	cap = runtime·roundupsize(s.len);
	b.array = runtime·mallocgc(cap, 0, FlagNoScan|FlagNoZero);
	b.len = s.len;
	b.cap = cap;
	runtime·memmove(b.array, s.str, s.len);
	if(cap != b.len)
		runtime·memclr(b.array+b.len, cap-b.len);
	FLUSH(&b);
}
Example #4
0
void
runtime·stringtoslicerune(String s, Slice b)
{
	b.array = 0;
	b.len = 0;
	b.cap = 0;
	FLUSH(&b);
#line 337 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc"

	intgo n;
	int32 dum, *r;
	uint8 *p, *ep;
	uintptr mem;

	// two passes.
	// unlike slicerunetostring, no race because strings are immutable.
	p = s.str;
	ep = s.str+s.len;
	n = 0;
	while(p < ep) {
		p += runtime·charntorune(&dum, p, ep-p);
		n++;
	}

	if(n > MaxMem/sizeof(r[0]))
		runtime·throw("out of memory");
	mem = runtime·roundupsize(n*sizeof(r[0]));
	b.array = runtime·mallocgc(mem, 0, FlagNoScan|FlagNoZero);
	b.len = n;
	b.cap = mem/sizeof(r[0]);
	p = s.str;
	r = (int32*)b.array;
	while(p < ep)
		p += runtime·charntorune(r++, p, ep-p);
	if(b.cap > b.len)
		runtime·memclr(b.array+b.len*sizeof(r[0]), (b.cap-b.len)*sizeof(r[0]));
	FLUSH(&b);
}