develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33578 - trunk/src/pmc

From:
pmichaud
Date:
December 6, 2008 13:46
Subject:
[svn:parrot] r33578 - trunk/src/pmc
Message ID:
20081206214603.D45B6CB9AF@x12.develooper.com
Author: pmichaud
Date: Sat Dec  6 13:46:03 2008
New Revision: 33578

Modified:
   trunk/src/pmc/capture.pmc

Log:
[core]:  Updates to Capture PMC
* Don't automatically create array/hash if simply fetching a value
* Allow set_pmc (setref op) to quickly release array/hash components


Modified: trunk/src/pmc/capture.pmc
==============================================================================
--- trunk/src/pmc/capture.pmc	(original)
+++ trunk/src/pmc/capture.pmc	Sat Dec  6 13:46:03 2008
@@ -29,7 +29,7 @@
     if (!PARROT_CAPTURE(obj)->hash) \
         PARROT_CAPTURE(obj)->hash = pmc_new((i), enum_class_Hash);
 
-pmclass Capture need_ext provides array provides hash {
+pmclass Capture need_ext {
     ATTR PMC *array;
     ATTR PMC *hash;
 
@@ -123,25 +123,29 @@
 */
 
     VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
-        CAPTURE_array_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->array))
+            return 0.0;
         return VTABLE_get_number_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
                                            key);
     }
 
     VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
-        CAPTURE_array_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->array))
+            return 0;
         return VTABLE_get_integer_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
                                             key);
     }
 
     VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
-        CAPTURE_array_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->array))
+            return PMCNULL;
         return VTABLE_get_pmc_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
                                         key);
     }
 
     VTABLE STRING *get_string_keyed_int(INTVAL key) {
-        CAPTURE_array_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->array))
+            return CONST_STRING(INTERP, "");
         return VTABLE_get_string_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
                                            key);
     }
@@ -380,23 +384,27 @@
 */
 
     VTABLE FLOATVAL get_number_keyed(PMC *key) {
-        CAPTURE_hash_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->hash))
+            return 0.0;
         return VTABLE_get_number_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
     }
 
     VTABLE INTVAL get_integer_keyed(PMC *key) {
-        CAPTURE_hash_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->hash))
+            return 0;
         return VTABLE_get_integer_keyed(INTERP, PARROT_CAPTURE(SELF)->hash,
                                         key);
     }
 
     VTABLE PMC *get_pmc_keyed(PMC *key) {
-        CAPTURE_hash_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->hash))
+            return PMCNULL;
         return VTABLE_get_pmc_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
     }
 
     VTABLE STRING *get_string_keyed(PMC *key) {
-        CAPTURE_hash_CREATE(INTERP, SELF);
+        if (!(PARROT_CAPTURE(SELF)->hash))
+            return CONST_STRING(INTERP, "");
         return VTABLE_get_string_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
     }
 
@@ -437,14 +445,19 @@
 
 =item C<void set_pmc(PMC *capture)>
 
-Set this capture to hold the value of another.
+Set this capture to hold the value of another.  If set to PMCNULL,
+erase the contents of the array and hash components.
 
 =cut
 
 */
 
     void set_pmc(PMC *capture) {
-        if (VTABLE_isa(INTERP, capture, CONST_STRING(INTERP, "Capture"))) {
+        if (PMC_IS_NULL(capture)) {
+            PARROT_CAPTURE(SELF)->array = NULL;
+            PARROT_CAPTURE(SELF)->hash = NULL;
+        }
+        else if (VTABLE_isa(INTERP, capture, CONST_STRING(INTERP, "Capture"))) {
             PARROT_CAPTURE(SELF)->array = PARROT_CAPTURE(capture)->array;
             PARROT_CAPTURE(SELF)->hash  = PARROT_CAPTURE(capture)->hash;
         }



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About