diff options
| author | Russ Cox <rsc@golang.org> | 2009-11-20 09:11:46 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-11-20 09:11:46 -0800 |
| commit | 0b471c4c0fdf44a4e354f21fcee1af058f95d31c (patch) | |
| tree | 500beae567fa23d8e061ccac78ba85f82a29c091 /src/pkg/runtime/slice.c | |
| parent | ead3d7280bc61be1f5729b4c4b3e719c853d52ff (diff) | |
| download | golang-0b471c4c0fdf44a4e354f21fcee1af058f95d31c.tar.gz | |
x[lo:] - gc and runtime.
* add runtime sliceslice1 for x[lo:]
* remove runtime arraytoslice, rewriting &arr into arr[0:len(arr)].
* port cgen_inline into 8g, 5g.
* use native memmove in maps
R=ken2
http://codereview.appspot.com/157106
Diffstat (limited to 'src/pkg/runtime/slice.c')
| -rw-r--r-- | src/pkg/runtime/slice.c | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c index 02839e27c..17762ae26 100644 --- a/src/pkg/runtime/slice.c +++ b/src/pkg/runtime/slice.c @@ -52,7 +52,6 @@ throwslice(uint32 lb, uint32 hb, uint32 n) void runtime·sliceslice(Slice old, uint32 lb, uint32 hb, uint32 width, Slice ret) { - if(hb > old.cap || lb > hb) { if(debug) { prints("runtime·sliceslice: old="); @@ -75,7 +74,7 @@ runtime·sliceslice(Slice old, uint32 lb, uint32 hb, uint32 width, Slice ret) } // new array is inside old array - ret.len = hb-lb; + ret.len = hb - lb; ret.cap = old.cap - lb; ret.array = old.array + lb*width; @@ -96,6 +95,49 @@ runtime·sliceslice(Slice old, uint32 lb, uint32 hb, uint32 width, Slice ret) } } +// sliceslice1(old []any, lb int, width int) (ary []any); +void +runtime·sliceslice1(Slice old, uint32 lb, uint32 width, Slice ret) +{ + if(lb > old.len) { + if(debug) { + prints("runtime·sliceslice: old="); + runtime·printslice(old); + prints("; lb="); + runtime·printint(lb); + prints("; width="); + runtime·printint(width); + prints("\n"); + + prints("oldarray: nel="); + runtime·printint(old.len); + prints("; cap="); + runtime·printint(old.cap); + prints("\n"); + } + throwslice(lb, old.len, old.cap); + } + + // new array is inside old array + ret.len = old.len - lb; + ret.cap = old.cap - lb; + ret.array = old.array + lb*width; + + FLUSH(&ret); + + if(debug) { + prints("runtime·sliceslice: old="); + runtime·printslice(old); + prints("; lb="); + runtime·printint(lb); + prints("; width="); + runtime·printint(width); + prints("; ret="); + runtime·printslice(ret); + prints("\n"); + } +} + // slicearray(old *any, nel int, lb int, hb int, width int) (ary []any); void runtime·slicearray(byte* old, uint32 nel, uint32 lb, uint32 hb, uint32 width, Slice ret) @@ -149,34 +191,6 @@ runtime·slicearray(byte* old, uint32 nel, uint32 lb, uint32 hb, uint32 width, S } } -// arraytoslice(old *any, nel int) (ary []any) -void -runtime·arraytoslice(byte* old, uint32 nel, Slice ret) -{ - if(nel > 0 && old == nil) { - // crash if old == nil. - // could give a better message - // but this is consistent with all the in-line checks - // that the compiler inserts for other uses. - *old = 0; - } - - // new dope to old array - ret.len = nel; - ret.cap = nel; - ret.array = old; - - FLUSH(&ret); - - if(debug) { - prints("runtime·slicearrayp: old="); - runtime·printpointer(old); - prints("; ret="); - runtime·printslice(ret); - prints("\n"); - } -} - // slicecopy(to any, fr any, wid uint32) int void runtime·slicecopy(Slice to, Slice fm, uintptr width, int32 ret) |
