summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorAndy Lester <andy@petdance.com>2005-05-16 05:13:53 -0500
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-05-16 16:56:43 +0000
commita3b680e6b77dd7f88268fad8b1dbdf4f641dd836 (patch)
tree5b6dc5a60baf7a56b2db73bf0faffe0c3c44963c /hv.c
parent02a44301bf4932369de0c75ad20a9c1256a455cd (diff)
downloadperl-a3b680e6b77dd7f88268fad8b1dbdf4f641dd836.tar.gz
consting-eleventy.patch: More consts, plus actual bug fix
Message-ID: <20050516151353.GA25387@petdance.com> p4raw-id: //depot/perl@24489
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/hv.c b/hv.c
index fa34b7077f..cafad726dc 100644
--- a/hv.c
+++ b/hv.c
@@ -527,7 +527,7 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
bool needs_store;
hv_magic_check (hv, &needs_copy, &needs_store);
if (needs_copy) {
- bool save_taint = PL_tainted;
+ const bool save_taint = PL_tainted;
if (keysv || is_utf8) {
if (!keysv) {
keysv = newSVpvn(key, klen);
@@ -788,7 +788,7 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
STATIC void
S_hv_magic_check(pTHX_ HV *hv, bool *needs_copy, bool *needs_store)
{
- MAGIC *mg = SvMAGIC(hv);
+ const MAGIC *mg = SvMAGIC(hv);
*needs_copy = FALSE;
*needs_store = TRUE;
while (mg) {
@@ -1052,13 +1052,11 @@ STATIC void
S_hsplit(pTHX_ HV *hv)
{
register XPVHV* xhv = (XPVHV*)SvANY(hv);
- I32 oldsize = (I32) xhv->xhv_max+1; /* HvMAX(hv)+1 (sick) */
+ const I32 oldsize = (I32) xhv->xhv_max+1; /* HvMAX(hv)+1 (sick) */
register I32 newsize = oldsize * 2;
register I32 i;
register char *a = xhv->xhv_array; /* HvARRAY(hv) */
register HE **aep;
- register HE **bep;
- register HE *entry;
register HE **oentry;
int longest_chain = 0;
int was_shared;
@@ -1105,6 +1103,8 @@ S_hsplit(pTHX_ HV *hv)
for (i=0; i<oldsize; i++,aep++) {
int left_length = 0;
int right_length = 0;
+ register HE *entry;
+ register HE **bep;
if (!*aep) /* non-existent */
continue;
@@ -1163,12 +1163,13 @@ S_hsplit(pTHX_ HV *hv)
aep = (HE **) xhv->xhv_array;
for (i=0; i<newsize; i++,aep++) {
- entry = *aep;
+ register HE *entry = *aep;
while (entry) {
/* We're going to trash this HE's next pointer when we chain it
into the new hash below, so store where we go next. */
HE *next = HeNEXT(entry);
UV hash;
+ HE **bep;
/* Rehash it */
PERL_HASH_INTERNAL(hash, HeKEY(entry), HeKLEN(entry));
@@ -1206,10 +1207,9 @@ void
Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
{
register XPVHV* xhv = (XPVHV*)SvANY(hv);
- I32 oldsize = (I32) xhv->xhv_max+1; /* HvMAX(hv)+1 (sick) */
+ const I32 oldsize = (I32) xhv->xhv_max+1; /* HvMAX(hv)+1 (sick) */
register I32 newsize;
register I32 i;
- register I32 j;
register char *a;
register HE **aep;
register HE *entry;
@@ -1265,6 +1265,7 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
if (!*aep) /* non-existent */
continue;
for (oentry = aep, entry = *aep; entry; entry = *oentry) {
+ register I32 j;
if ((j = (HeHASH(entry) & newsize)) != i) {
j -= i;
*oentry = HeNEXT(entry);
@@ -1324,7 +1325,7 @@ Perl_newHVhv(pTHX_ HV *ohv)
if (!SvMAGICAL((SV *)ohv)) {
/* It's an ordinary hash, so copy it fast. AMS 20010804 */
STRLEN i;
- bool shared = !!HvSHAREKEYS(ohv);
+ const bool shared = !!HvSHAREKEYS(ohv);
HE **ents, **oents = (HE **)HvARRAY(ohv);
char *a;
New(0, a, PERL_HV_ARRAY_ALLOC_BYTES(hv_max+1), char);
@@ -1341,10 +1342,10 @@ Perl_newHVhv(pTHX_ HV *ohv)
/* Copy the linked list of entries. */
for (oent = oents[i]; oent; oent = HeNEXT(oent)) {
- U32 hash = HeHASH(oent);
- char *key = HeKEY(oent);
- STRLEN len = HeKLEN(oent);
- int flags = HeKFLAGS(oent);
+ const U32 hash = HeHASH(oent);
+ const char * const key = HeKEY(oent);
+ const STRLEN len = HeKLEN(oent);
+ const int flags = HeKFLAGS(oent);
ent = new_HE();
HeVAL(ent) = newSVsv(HeVAL(oent));
@@ -1368,8 +1369,8 @@ Perl_newHVhv(pTHX_ HV *ohv)
else {
/* Iterate over ohv, copying keys and values one at a time. */
HE *entry;
- I32 riter = HvRITER(ohv);
- HE *eiter = HvEITER(ohv);
+ const I32 riter = HvRITER(ohv);
+ HE * const eiter = HvEITER(ohv);
/* Can we use fewer buckets? (hv_max is always 2^n-1) */
while (hv_max && hv_max + 1 >= hv_fill * 2)
@@ -1453,9 +1454,8 @@ Perl_hv_clear(pTHX_ HV *hv)
if (SvREADONLY(hv) && xhv->xhv_array != NULL) {
/* restricted hash: convert all keys to placeholders */
I32 i;
- HE* entry;
for (i = 0; i <= (I32) xhv->xhv_max; i++) {
- entry = ((HE**)xhv->xhv_array)[i];
+ HE *entry = ((HE**)xhv->xhv_array)[i];
for (; entry; entry = HeNEXT(entry)) {
/* not already placeholder */
if (HeVAL(entry) != &PL_sv_placeholder) {
@@ -1515,7 +1515,7 @@ Perl_hv_clear_placeholders(pTHX_ HV *hv)
do {
/* Loop down the linked list heads */
- int first = 1;
+ bool first = 1;
HE **oentry = &(HvARRAY(hv))[i];
HE *entry = *oentry;
@@ -1556,7 +1556,6 @@ S_hfreeentries(pTHX_ HV *hv)
{
register HE **array;
register HE *entry;
- register HE *oentry = Null(HE*);
I32 riter;
I32 max;
@@ -1577,7 +1576,7 @@ S_hfreeentries(pTHX_ HV *hv)
entry = array[0];
for (;;) {
if (entry) {
- oentry = entry;
+ register HE *oentry = entry;
entry = HeNEXT(entry);
hv_free_ent(hv, oentry);
}
@@ -1837,7 +1836,7 @@ Perl_hv_iterkeysv(pTHX_ register HE *entry)
{
if (HeKLEN(entry) != HEf_SVKEY) {
HEK *hek = HeKEY_hek(entry);
- int flags = HEK_FLAGS(hek);
+ const int flags = HEK_FLAGS(hek);
SV *sv;
if (flags & HVhek_WASUTF8) {
@@ -1887,7 +1886,8 @@ Perl_hv_iterval(pTHX_ HV *hv, register HE *entry)
SV* sv = sv_newmortal();
if (HeKLEN(entry) == HEf_SVKEY)
mg_copy((SV*)hv, sv, (char*)HeKEY_sv(entry), HEf_SVKEY);
- else mg_copy((SV*)hv, sv, HeKEY(entry), HeKLEN(entry));
+ else
+ mg_copy((SV*)hv, sv, HeKEY(entry), HeKLEN(entry));
return sv;
}
}
@@ -1964,7 +1964,7 @@ S_unshare_hek_or_pvn(pTHX_ HEK *hek, const char *str, I32 len, U32 hash)
register HE *entry;
register HE **oentry;
register I32 i = 1;
- I32 found = 0;
+ bool found = 0;
bool is_utf8 = FALSE;
int k_flags = 0;
const char *save = str;
@@ -2145,7 +2145,7 @@ Perl_hv_assert(pTHX_ HV *hv)
int placeholders = 0;
int real = 0;
int bad = 0;
- I32 riter = HvRITER(hv);
+ const I32 riter = HvRITER(hv);
HE *eiter = HvEITER(hv);
(void)hv_iterinit(hv);