[svn:parrot] r39755 - branches/tt761_keys_revamp/src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Jun 24 10:24:47 UTC 2009


Author: bacek
Date: Wed Jun 24 10:24:47 2009
New Revision: 39755
URL: https://trac.parrot.org/parrot/changeset/39755

Log:
[pmc] Hash.get_pmc_keyed* migrated to MULTIs.

Modified:
   branches/tt761_keys_revamp/src/pmc/hash.pmc

Modified: branches/tt761_keys_revamp/src/pmc/hash.pmc
==============================================================================
--- branches/tt761_keys_revamp/src/pmc/hash.pmc	Wed Jun 24 10:24:27 2009	(r39754)
+++ branches/tt761_keys_revamp/src/pmc/hash.pmc	Wed Jun 24 10:24:47 2009	(r39755)
@@ -1030,29 +1030,44 @@
         return hash_value_to_pmc(INTERP, hash, b->value);
     }
 
-    VTABLE PMC *get_pmc_keyed(PMC *key) {
-        const Hash * const hash = (Hash *)SELF.get_pointer();
-        void          *keystr;
-        HashBucket    *b;
-        PMC           *nextkey;
-
-        /* called from iterator */
-        if (VTABLE_type(INTERP, key) == enum_class_HashIteratorKey) {
-            return (PMC*)PARROT_HASHITERATORKEY(key)->bucket->value;
-        }
+    /* Called from HashIterator */
+    MULTI PMC *get_pmc_keyed(HashIteratorKey key) {
+        void *value = (PMC*)PARROT_HASHITERATORKEY(key)->bucket->value;
+        return hash_value_to_pmc(INTERP, (Hash*)SELF.get_pointer(), value);
+    }
 
-        keystr = hash_key_from_pmc(INTERP, hash, key);
-        b      = parrot_hash_get_bucket(INTERP, hash, keystr);
+    /* Simple PMC */
+    MULTI PMC *get_pmc_keyed(DEFAULT key) {
+        const Hash * const hash = (Hash*)SELF.get_pointer();
+        HashBucket * const b    = parrot_hash_get_bucket(INTERP, hash,
+                hash_key_from_pmc(INTERP, hash, key));
 
         if (!b)
             return PMCNULL;
 
-        nextkey = key_next(INTERP, key);
+        return hash_value_to_pmc(INTERP, hash, b->value);
+    }
+
+    /* Compound Key */
+    MULTI PMC *get_pmc_keyed(Key key) {
+        const Hash * const hash = (Hash *)SELF.get_pointer();
+        HashBucket *b = parrot_hash_get_bucket(INTERP, hash,
+                hash_key_from_pmc(INTERP, hash, key));
+        PMC        *valpmc;
+        PMC        *nextkey;
+
+        if (!b)
+            return PMCNULL;
+
+        nextkey = VTABLE_shift_pmc(INTERP, key);
+        valpmc  = hash_value_to_pmc(INTERP, hash, b->value);
 
+        /* Stop recursion. This is last step */
         if (!nextkey)
-            return (PMC *)b->value;
+            return valpmc;
 
-        return VTABLE_get_pmc_keyed(INTERP, (PMC*)b->value, nextkey);
+        /* Recusively call to enclosed aggregate */
+        return VTABLE_get_pmc_keyed(INTERP, valpmc, nextkey);
     }
 
 /*


More information about the parrot-commits mailing list