> This patch is rather questionable, and thus I did not commit it
> directly. However, it illustrates a point I wanted to make.
Doh! Hopefully my previous post will make a bit more sense now. :)
Mike Lambert
Index: array.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/array.pmc,v
retrieving revision 1.28
diff -u -r1.28 array.pmc
--- array.pmc 24 Jul 2002 07:32:46 -0000 1.28
+++ array.pmc 25 Jul 2002 03:24:31 -0000
@@ -146,46 +146,16 @@
}
INTVAL get_integer_keyed (KEY* key) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
+ PMC *value = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
-
- if(key->next != NULL) {
+ if(key->next != NULL)
return value->vtable->get_integer_keyed(INTERP, value, key->next);
- }
- else {
+ else
return value->vtable->get_integer(INTERP, value);
- }
}
INTVAL get_integer_keyed_int (INTVAL* key) {
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
return value->vtable->get_integer(INTERP, value);
}
@@ -194,46 +164,16 @@
}
FLOATVAL get_number_keyed (KEY* key) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* value;
+ PMC *value = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
- if (!key) {
- return 0;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
-
- if(key->next != NULL) {
+ if(key->next != NULL)
return value->vtable->get_number_keyed(INTERP, value, key->next);
- }
- else {
+ else
return value->vtable->get_number(INTERP, value);
- }
}
FLOATVAL get_number_keyed_int (INTVAL* key) {
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
return value->vtable->get_number(INTERP, value);
}
@@ -243,46 +183,16 @@
}
BIGNUM* get_bignum_keyed (KEY* key) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* value;
+ PMC *value = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
- if (!key) {
- return 0;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
-
- if(key->next != NULL) {
+ if(key->next != NULL)
return value->vtable->get_bignum_keyed(INTERP, value, key->next);
- }
- else {
+ else
return value->vtable->get_bignum(INTERP, value);
- }
}
BIGNUM* get_bignum_keyed_int (INTVAL* key) {
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
return value->vtable->get_bignum(INTERP, value);
}
@@ -291,46 +201,16 @@
}
STRING* get_string_keyed (KEY * key) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
+ PMC *value = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
-
- if(key->next != NULL) {
+ if(key->next != NULL)
return value->vtable->get_string_keyed(INTERP, value, key->next);
- }
- else {
+ else
return value->vtable->get_string(INTERP, value);
- }
}
STRING* get_string_keyed_int (INTVAL * key) {
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
return value->vtable->get_string(INTERP, value);
}
@@ -339,46 +219,16 @@
}
INTVAL get_bool_keyed (KEY* key) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* value;
+ PMC *value = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
- if (!key) {
- return 0;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
-
- if(key->next != NULL) {
+ if(key->next != NULL)
return value->vtable->get_bool_keyed(INTERP, value, key->next);
- }
- else {
+ else
return value->vtable->get_bool(INTERP, value);
- }
}
INTVAL get_bool_keyed_int (INTVAL* key) {
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
return value->vtable->get_bool(INTERP, value);
}
@@ -388,46 +238,16 @@
}
INTVAL elements_keyed (KEY* key) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
- if(key->next != NULL) {
+ if(key->next != NULL)
return value->vtable->elements_keyed(INTERP, value, key->next);
- }
- else {
+ else
return value->vtable->elements(INTERP, value);
- }
}
INTVAL elements_keyed_int (INTVAL* key) {
- INTVAL ix;
- PMC* value;
-
- if (!key) {
- return 0;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- value = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC *value = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
return value->vtable->elements(INTERP, value);
}
@@ -514,47 +334,16 @@
}
void set_integer_keyed (KEY* key, INTVAL value) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* mypmc;
-
- if (!key) {
- return;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- mypmc = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
-
- if(key->next != NULL) {
- mypmc->vtable->set_integer_keyed(INTERP, mypmc, key->next, value);
- }
- else {
- mypmc->vtable->set_integer_native(INTERP, mypmc, value);
- }
+ PMC *dest = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
+ if(key->next != NULL)
+ dest->vtable->set_integer_keyed(INTERP, dest, key->next, value);
+ else
+ dest->vtable->set_integer_native(INTERP, dest, value);
}
void set_integer_keyed_int (INTVAL* key, INTVAL value) {
- INTVAL ix;
- PMC* mypmc;
-
- if (!key) {
- return;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- mypmc = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
- mypmc->vtable->set_integer_native(INTERP, mypmc, value);
+ PMC *dest = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
+ dest->vtable->set_integer_native(INTERP, dest, value);
}
void set_number (PMC * value) {
@@ -576,89 +365,29 @@
}
void set_number_keyed (KEY * key, FLOATVAL value) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* mypmc;
-
- if (!key) {
- return;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- mypmc = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
- if(key->next != NULL) {
- mypmc->vtable->set_number_keyed(INTERP, mypmc, key->next, value);
- }
- else {
- mypmc->vtable->set_number_native(INTERP, mypmc, value);
- }
+ PMC *dest = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
+ if(key->next != NULL)
+ dest->vtable->set_number_keyed(INTERP, dest, key->next, value);
+ else
+ dest->vtable->set_number_native(INTERP, dest, value);
}
void set_number_keyed_int (INTVAL * key, FLOATVAL value) {
- INTVAL ix;
- PMC* mypmc;
-
- if (!key) {
- return;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- mypmc = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
- mypmc->vtable->set_number_native(INTERP, mypmc, value);
+ PMC *dest = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
+ dest->vtable->set_number_native(INTERP, dest, value);
}
void set_string_keyed (KEY * key, STRING * value) {
- KEY_ATOM* kp;
- INTVAL ix;
- PMC* mypmc;
-
- if (!key) {
- return;
- }
-
- kp = &key->atom;
- ix = atom2int(INTERP, kp);
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- mypmc = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
- if(key->next != NULL) {
- mypmc->vtable->set_string_keyed(INTERP, mypmc, key->next, value);
- }
- else {
- mypmc->vtable->set_string_native(INTERP, mypmc, value);
- }
+ PMC *dest = SELF->vtable->get_pmc_keyed(INTERP, SELF, key);
+ if(key->next != NULL)
+ dest->vtable->set_string_keyed(INTERP, dest, key->next, value);
+ else
+ dest->vtable->set_string_native(INTERP, dest, value);
}
void set_string_keyed_int (INTVAL * key, STRING * value) {
- INTVAL ix;
- PMC* mypmc;
-
- if (!key) {
- return;
- }
-
- ix = *key;
-
- if (ix >= SELF->cache.int_val || ix < 0) {
- internal_exception(OUT_OF_BOUNDS, "Array element out of bounds!\n");
- }
-
- mypmc = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
- mypmc->vtable->set_string_native(INTERP, mypmc, value);
+ PMC *dest = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, key);
+ dest->vtable->set_string_native(INTERP, dest, value);
}
void set_pmc_keyed(KEY * dest_key, PMC* src, KEY* src_key) {
@@ -666,8 +395,7 @@
src = src->vtable->get_pmc_keyed(INTERP, src, src_key);
}
if (dest_key) {
- INTVAL ix = atom2int(INTERP, &dest_key->atom);
- PMC* dest = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC* dest = SELF->vtable->get_pmc_keyed(INTERP, SELF, dest_key);
dest->vtable->set_pmc(INTERP, dest, src);
}
else {
@@ -681,8 +409,7 @@
src = src->vtable->get_pmc_keyed_int(INTERP, src, src_key);
}
if (dest_key) {
- INTVAL ix = *dest_key;
- PMC* dest = ((PMC**)(((Buffer *)SELF->data)->bufstart))[ix];
+ PMC* dest = SELF->vtable->get_pmc_keyed_int(INTERP, SELF, dest_key);
dest->vtable->set_pmc(INTERP, dest, src);
}
else {