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

bacek at svn.parrot.org bacek at svn.parrot.org
Sat Oct 10 00:16:38 UTC 2009


Author: bacek
Date: Sat Oct 10 00:16:37 2009
New Revision: 41779
URL: https://trac.parrot.org/parrot/changeset/41779

Log:
[cage] Don't use C strings in Sub.__get_regs_used.

Modified:
   trunk/src/pmc/sub.pmc

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc	Fri Oct  9 23:35:06 2009	(r41778)
+++ trunk/src/pmc/sub.pmc	Sat Oct 10 00:16:37 2009	(r41779)
@@ -997,29 +997,26 @@
 
         /* TODO switch to canonical NiSP order
          * see also imcc/reg_alloc.c */
-        static const char types[] = "INSP";
-        char *p;
+        STRING                *types = CONST_STRING(INTERP, "INSP");
         Parrot_Sub_attributes *sub;
-        char          * const kind = Parrot_str_to_cstring(interp, reg);
-        INTVAL                regs_used;
+        INTVAL                 regs_used;
+        INTVAL                 kind;
 
         PMC_get_sub(INTERP, SELF, sub);
         PARROT_ASSERT(sub->n_regs_used);
 
-        if (!*kind || kind[1]) {
-            Parrot_str_free_cstring(kind);
+        if (!reg || Parrot_str_length(INTERP, reg) != 1) {
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
                 "illegal register kind '%Ss'", reg);
         }
 
-        p = strchr(types, *kind);
-        Parrot_str_free_cstring(kind);
+        kind = Parrot_str_find_index(INTERP, types, reg, 0);
 
-        if (!p)
+        if (kind == -1)
             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
                 "illegal register kind '%Ss'", reg);
 
-        regs_used = sub->n_regs_used[p - types];
+        regs_used = sub->n_regs_used[kind];
         RETURN(INTVAL regs_used);
     }
 


More information about the parrot-commits mailing list