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
https://golang.org/cl/157106
diff --git a/src/pkg/runtime/hashmap.h b/src/pkg/runtime/hashmap.h
index 984b80c..9d821da 100644
--- a/src/pkg/runtime/hashmap.h
+++ b/src/pkg/runtime/hashmap.h
@@ -67,7 +67,6 @@
#define free(a) USED(a)
#define offsetof(s,m) (uint32)(&(((s*)0)->m))
#define memset(a,b,c) runtime·memclr((byte*)(a), (uint32)(c))
-#define memmove(a,b,c) mmov((byte*)(a),(byte*)(b),(uint32)(c))
#define memcpy(a,b,c) mcpy((byte*)(a),(byte*)(b),(uint32)(c))
#define assert(a) if(!(a)) throw("assert")
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c
index 39fda98..4a0309e 100644
--- a/src/pkg/runtime/runtime.c
+++ b/src/pkg/runtime/runtime.c
@@ -104,28 +104,6 @@
}
-void
-mmov(byte *t, byte *f, uint32 n)
-{
- if(t < f) {
- while(n > 0) {
- *t = *f;
- t++;
- f++;
- n--;
- }
- } else {
- t += n;
- f += n;
- while(n > 0) {
- t--;
- f--;
- *t = *f;
- n--;
- }
- }
-}
-
byte*
mchr(byte *p, byte c, byte *ep)
{
diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h
index df1c45a..11dc489 100644
--- a/src/pkg/runtime/runtime.h
+++ b/src/pkg/runtime/runtime.h
@@ -342,7 +342,7 @@
byte* mchr(byte*, byte, byte*);
void mcpy(byte*, byte*, uint32);
int32 mcmp(byte*, byte*, uint32);
-void mmov(byte*, byte*, uint32);
+void memmove(void*, void*, uint32);
void* mal(uint32);
uint32 cmpstring(String, String);
String gostring(byte*);
diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c
index 02839e2..17762ae 100644
--- a/src/pkg/runtime/slice.c
+++ b/src/pkg/runtime/slice.c
@@ -52,7 +52,6 @@
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 @@
}
// 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 @@
}
}
+// 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 @@
}
}
-// 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)