Optimize for fast-path in Array >> at: / at:put:
Avoid jumps in Array >> at: / at:put: for common case the
receiver is an instance of Array and thus has no instance
variables.
--- a/Array.st Mon Apr 20 17:22:40 2015 +0100
+++ b/Array.st Tue Apr 21 10:47:35 2015 +0100
@@ -321,15 +321,18 @@
if (__isSmallInteger(index)) {
indx = __intVal(index) - 1;
slf = self;
-
+ cls = __qClass(slf);
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE);
- if ((cls = __qClass(slf)) != Array) {
- if (indx < 0) goto badIndex;
- indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ if (cls == Array) {
+ fetch:
+ if ((unsigned INT)indx < (unsigned INT)nIndex) {
+ RETURN ( __InstPtr(slf)->i_instvars[indx] );
+ }
+ goto badIndex;
}
- if ((unsigned INT)indx < (unsigned INT)nIndex) {
- RETURN ( __InstPtr(slf)->i_instvars[indx] );
- }
+ if (indx < 0) goto badIndex;
+ indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ goto fetch;
}
badIndex: ;
%}.
@@ -355,17 +358,20 @@
if (__isSmallInteger(index)) {
indx = __intVal(index) - 1;
slf = self;
-
+ cls = __qClass(slf);
nIndex = __BYTES2OBJS__(__qSize(slf) - OHDR_SIZE);
- if ((cls = __qClass(slf)) != Array) {
- if (indx < 0) goto badIndex;
- indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ if (cls == Array) {
+ store:
+ if ((unsigned INT)indx < (unsigned INT)nIndex) {
+ __InstPtr(slf)->i_instvars[indx] = anObject;
+ __STORE(slf, anObject);
+ RETURN ( anObject );
+ }
+ goto badIndex;
}
- if ((unsigned INT)indx < (unsigned INT)nIndex) {
- __InstPtr(slf)->i_instvars[indx] = anObject;
- __STORE(slf, anObject);
- RETURN ( anObject );
- }
+ if (indx < 0) goto badIndex;
+ indx += __intVal(__ClassInstPtr(cls)->c_ninstvars);
+ goto store;
}
badIndex: ;
%}.