Shift negative klen/flags games from hv_fetch_common out to hv_fetch
authorNicholas Clark <nick@ccl4.org>
Thu, 20 Nov 2003 22:34:00 +0000 (22:34 +0000)
committerNicholas Clark <nick@ccl4.org>
Thu, 20 Nov 2003 22:34:00 +0000 (22:34 +0000)
p4raw-id: //depot/perl@21760

embed.fnc
hv.c
proto.h

index ce814e3..ee667f2 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1396,7 +1396,7 @@ Apod      |void   |hv_assert      |HV* tb
 #if defined(PERL_IN_HV_C) || defined(PERL_DECL_PROT)
 sM     |SV*    |hv_delete_common|HV* tb|SV* key_sv|const char* key|I32 klen|I32 flags|U32 hash
 sM     |bool   |hv_exists_common|HV* tb|SV* key_sv|const char* key|I32 klen|U32 hash
-sM     |HE*    |hv_fetch_common|HV* tb|SV* key_sv|const char* key|I32 klen|int flags|int action|U32 hash
+sM     |HE*    |hv_fetch_common|HV* tb|SV* key_sv|const char* key|STRLEN klen|int flags|int action|U32 hash
 sM     |HE*    |hv_store_common|HV* tb|SV* key_sv|const char* key|I32 klen|int flags|SV* val|U32 hash
 #endif
 
diff --git a/hv.c b/hv.c
index ece146d..8c345c7 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -186,11 +186,21 @@ information on how to use this function on tied hashes.
 #define HV_FETCH_JUST_SV 0x02
 
 SV**
-Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen, I32 lval)
+Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 lval)
 {
-    HE *hek = hv_fetch_common (hv, NULL, key, klen, 0,
-                              HV_FETCH_JUST_SV | (lval ? HV_FETCH_LVALUE : 0),
-                              0);
+    HE *hek;
+    STRLEN klen;
+    int flags;
+
+    if (klen_i32 < 0) {
+       klen = -klen_i32;
+       flags = HVhek_UTF8;
+    } else {
+       klen = klen_i32;
+       flags = 0;
+    }
+    hek = hv_fetch_common (hv, NULL, key, klen, flags,
+                          HV_FETCH_JUST_SV | (lval ? HV_FETCH_LVALUE : 0), 0);
     return hek ? &HeVAL(hek) : NULL;
 }
 
@@ -221,11 +231,10 @@ Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, register U32 hash)
 }
 
 HE *
-S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, I32 klen_i32,
+S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
                  int flags, int action, register U32 hash)
 {
     register XPVHV* xhv;
-    STRLEN klen;
     register HE *entry;
     SV *sv;
     bool is_utf8;
@@ -237,15 +246,10 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, I32 klen_i32,
 
     if (keysv) {
        key = SvPV(keysv, klen);
+       flags = 0;
        is_utf8 = (SvUTF8(keysv) != 0);
     } else {
-       if (klen_i32 < 0) {
-           klen = -klen_i32;
-           is_utf8 = TRUE;
-       } else {
-           klen = klen_i32;
-           is_utf8 = FALSE;
-       }
+       is_utf8 = ((flags & HVhek_UTF8) ? TRUE : FALSE);
     }
     keysave = key;
 
@@ -334,7 +338,9 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, I32 klen_i32,
        int oldflags = flags;
        key = (char*)bytes_from_utf8((U8*)key, &klen, &is_utf8);
         if (is_utf8)
-            flags = HVhek_UTF8;
+           flags |= HVhek_UTF8;
+       else
+           flags &= ~HVhek_UTF8;
         if (key != keysave)
             flags |= HVhek_WASUTF8 | HVhek_FREEKEY;
        if (oldflags & HVhek_FREEKEY)
diff --git a/proto.h b/proto.h
index fc50181..ea5219a 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -1337,7 +1337,7 @@ PERL_CALLCONV void        Perl_hv_assert(pTHX_ HV* tb);
 #if defined(PERL_IN_HV_C) || defined(PERL_DECL_PROT)
 STATIC SV*     S_hv_delete_common(pTHX_ HV* tb, SV* key_sv, const char* key, I32 klen, I32 flags, U32 hash);
 STATIC bool    S_hv_exists_common(pTHX_ HV* tb, SV* key_sv, const char* key, I32 klen, U32 hash);
-STATIC HE*     S_hv_fetch_common(pTHX_ HV* tb, SV* key_sv, const char* key, I32 klen, int flags, int action, U32 hash);
+STATIC HE*     S_hv_fetch_common(pTHX_ HV* tb, SV* key_sv, const char* key, STRLEN klen, int flags, int action, U32 hash);
 STATIC HE*     S_hv_store_common(pTHX_ HV* tb, SV* key_sv, const char* key, I32 klen, int flags, SV* val, U32 hash);
 #endif