Andy Wardley sent the following bits through the ether:

> Doug, you totally, totally, rock!  (And not for the first time... :-)

I totally agree! Passes all the tests and everything!

So now for the first patch ;-) This takes away is_str_an_integer and
uses SvIV instead of atol... 

Leon
-- 
Leon Brocard.............................http://www.astray.com/
Iterative Software...........http://www.iterative-software.com/

... Always remember you're unique, just like everyone else
--- Stash.xs.orig       Tue Aug 21 12:42:10 2001
+++ Stash.xs    Tue Aug 21 13:07:35 2001
@@ -72,7 +72,6 @@
 static SV*     do_getset(SV*, AV*, SV*, int);
 static AV*     convert_dotted_string(const char*, I32);
 static int     get_debug_flag (SV*);
-static int     is_str_an_integer(char*);
 static int     cmp_arg __P((const void *, const void *));
 static void    die_object(SV *);
 static struct xs_arg *find_xs_op(char *);
@@ -298,14 +297,6 @@
 
 
 
-/* returns true if string contains only digits */
-static int is_str_an_integer(char *s) {
-    if (!s) return 0;
-    while (isDIGIT(*s)) s++;
-    return(!*s);
-}
-
-
 /* retrieves an item from the given hash or array ref.
  * if found:
  *   if a coderef, the coderef will be called and passed args
@@ -326,8 +317,7 @@
        break;
 
     case SVt_PVAV:
-       if (is_str_an_integer(key))
-           value = av_fetch((AV *) SvRV(root), (I32) atol(key), FALSE);
+       value = av_fetch((AV *) SvRV(root), SvIV(key_sv), FALSE);
        break;
     }
 
@@ -460,8 +450,7 @@
                    for (i = 0; i <= av_len(k_av); i++) {
                        if ((svp = av_fetch(k_av, i, FALSE))) {
                            t = SvPV(*svp, tlen);
-                           if (is_str_an_integer(t) &&
-                               (svp = av_fetch(r_av, atol(t), FALSE)))
+                           if ((svp = av_fetch(r_av, SvIV(*svp), FALSE)))
                                    av_push(a_av, SvREFCNT_inc(*svp));
                        }
                    }
@@ -659,17 +648,13 @@
        case SVt_PVAV:                              /* ARRAY */
            rootav = (AV *) SvRV(root);
 
-           /* examine the key to see if it looks like an integer */
-           if (!is_str_an_integer(key))
-               croak("can't assign to item '%s' in a list", key);
-           
            /* check for any existing value if default flag set */
            if ((flags & TT_DEFAULT_FLAG)
-               && (svp = av_fetch(rootav, atol(key), FALSE))
+               && (svp = av_fetch(rootav, SvIV(key_sv), FALSE))
                && SvTRUE(*svp))
                return &PL_sv_undef;
 
-           if (av_store(rootav, atol(key), value))
+           if (av_store(rootav, SvIV(key_sv), value))
                return SvREFCNT_inc(value);
            else
                return &PL_sv_undef;

Reply via email to