Ticket #1741: 0004-get-rid-of-parrot_hash_get_idx-very-ugly-crap.patch
| File 0004-get-rid-of-parrot_hash_get_idx-very-ugly-crap.patch, 5.8 KB (added by luben, 3 years ago) |
|---|
-
include/parrot/hash.h
From d45a39ba5b98f6eef21a183fb735320c2ca20dac Mon Sep 17 00:00:00 2001 From: luben <karavelov@spnet.net> Date: Sun, 15 Aug 2010 01:38:18 +0300 Subject: [PATCH 4/7] get rid of parrot_hash_get_idx : very ugly crap replace with hash iteraton macros --- include/parrot/hash.h | 19 -------------- src/call/args.c | 22 ++++----------- src/hash.c | 67 ------------------------------------------------- src/pmc/null.pmc | 2 - 4 files changed, 6 insertions(+), 104 deletions(-) diff --git a/include/parrot/hash.h b/include/parrot/hash.h index c23afa6..e8eff3d 100644
a b 19 19 } HashEntryType; 20 20 21 21 22 /* A BucketIndex is an index into the pool of available buckets. */23 typedef UINTVAL BucketIndex;24 #define INITBucketIndex ((BucketIndex)-2)25 26 22 #define N_BUCKETS(n) ((n)) 27 23 #define HASH_ALLOC_SIZE(n) (N_BUCKETS(n) * sizeof (HashBucket) + \ 28 24 (n) * sizeof (HashBucket *)) … … 191 187 __attribute__nonnull__(2); 192 188 193 189 PARROT_EXPORT 194 PARROT_WARN_UNUSED_RESULT195 PARROT_CAN_RETURN_NULL196 void * parrot_hash_get_idx(PARROT_INTERP,197 ARGIN(const Hash *hash),198 ARGMOD(PMC *key))199 __attribute__nonnull__(1)200 __attribute__nonnull__(2)201 __attribute__nonnull__(3)202 FUNC_MODIFIES(*key);203 204 PARROT_EXPORT205 190 PARROT_IGNORABLE_RESULT 206 191 PARROT_CANNOT_RETURN_NULL 207 192 HashBucket* parrot_hash_put(PARROT_INTERP, … … 469 454 #define ASSERT_ARGS_parrot_hash_get_bucket __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 470 455 PARROT_ASSERT_ARG(interp) \ 471 456 , PARROT_ASSERT_ARG(hash)) 472 #define ASSERT_ARGS_parrot_hash_get_idx __attribute__unused__ int _ASSERT_ARGS_CHECK = (\473 PARROT_ASSERT_ARG(interp) \474 , PARROT_ASSERT_ARG(hash) \475 , PARROT_ASSERT_ARG(key))476 457 #define ASSERT_ARGS_parrot_hash_put __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 477 458 PARROT_ASSERT_ARG(interp) \ 478 459 , PARROT_ASSERT_ARG(hash)) -
src/call/args.c
diff --git a/src/call/args.c b/src/call/args.c index d432caa..c87ea8f 100644
a b 488 488 } 489 489 } 490 490 else if (VTABLE_does(interp, aggregate, CONST_STRING(interp, "hash"))) { 491 const INTVAL elements = VTABLE_elements(interp, aggregate); 492 INTVAL index; 493 PMC * const key = Parrot_pmc_new(interp, enum_class_Key); 494 VTABLE_set_integer_native(interp, key, 0); 495 SETATTR_Key_next_key(interp, key, (PMC *)INITBucketIndex); 496 497 /* Low-level hash iteration. */ 498 for (index = 0; index < elements; ++index) { 499 if (!PMC_IS_NULL(key)) { 500 STRING * const name = (STRING *)parrot_hash_get_idx(interp, 501 (Hash *)VTABLE_get_pointer(interp, aggregate), key); 502 PARROT_ASSERT(name); 503 VTABLE_set_pmc_keyed_str(interp, call_object, name, 504 VTABLE_get_pmc_keyed_str(interp, aggregate, name)); 505 } 506 } 491 Hash * hash = (Hash *)VTABLE_get_pointer(interp, aggregate), key; 492 parrot_hash_iterate(hash, 493 PARROT_ASSERT(_bucket->key); 494 VTABLE_set_pmc_keyed_str(interp,call_object,_bucket->key, 495 VTABLE_get_pmc_keyed_str(interp, aggregate, _bucket->key)); 496 ); 507 497 } 508 498 else { 509 499 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, -
src/hash.c
diff --git a/src/hash.c b/src/hash.c index f5b73f5..2ff52c4 100644
a b 1152 1152 return hash->entries; 1153 1153 } 1154 1154 1155 1156 /*1157 1158 =item C<void * parrot_hash_get_idx(PARROT_INTERP, const Hash *hash, PMC *key)>1159 1160 Finds the next index into the hash's internal storage for the given Key. Used1161 by iterators. Ugly.1162 1163 =cut1164 1165 */1166 1167 PARROT_EXPORT1168 PARROT_WARN_UNUSED_RESULT1169 PARROT_CAN_RETURN_NULL1170 void *1171 parrot_hash_get_idx(PARROT_INTERP, ARGIN(const Hash *hash), ARGMOD(PMC *key))1172 {1173 ASSERT_ARGS(parrot_hash_get_idx)1174 HashBucket *b;1175 void *res;1176 INTVAL i = VTABLE_get_integer(interp, key);1177 PMC *fake_bi;1178 BucketIndex bi;1179 1180 /* idx directly in the bucket store, which is at negative1181 * address from the data pointer */1182 /* locate initial */1183 const INTVAL size = (INTVAL)N_BUCKETS(hash->mask + 1);1184 1185 GETATTR_Key_next_key(interp, key, fake_bi);1186 bi = (BucketIndex)fake_bi;1187 1188 if (bi == INITBucketIndex) {1189 i = 0;1190 SETATTR_Key_next_key(interp, key, NULL);1191 }1192 else if (i >= size || i < 0) {1193 /* NOTE: These instances of SETATTR_Key_int_key can't be VTABLE1194 * functions because of the "special" way hash iterators work. */1195 SETATTR_Key_int_key(interp, key, -1);1196 return NULL;1197 }1198 1199 res = NULL;1200 1201 for (b = hash->buckets + i; i < size ; ++i, ++b) {1202 /* XXX int keys may be zero - use different iterator */1203 if (b->key) {1204 if (!res)1205 res = b->key;1206 1207 /* found next key - FIXME hash iter does auto next */1208 else1209 break;1210 }1211 }1212 1213 if (i >= size)1214 i = -1;1215 1216 SETATTR_Key_int_key(interp, key, i);1217 1218 return res;1219 }1220 1221 1222 1155 /* 1223 1156 1224 1157 =item C<HashBucket * parrot_hash_get_bucket(PARROT_INTERP, const Hash *hash, -
src/pmc/null.pmc
diff --git a/src/pmc/null.pmc b/src/pmc/null.pmc index ac0a73c..581424a 100644
a b 36 36 37 37 =item C<static void null_pmc_access(PARROT_INTERP, int index)> 38 38 39 40 41 39 =cut 42 40 43 41 */
