[svn:parrot] r49418 - in trunk: include/parrot src src/pmc src/string src/string/encoding
nwellnhof at svn.parrot.org
nwellnhof at svn.parrot.org
Sat Oct 2 22:26:47 UTC 2010
Author: nwellnhof
Date: Sat Oct 2 22:26:47 2010
New Revision: 49418
URL: https://trac.parrot.org/parrot/changeset/49418
Log:
[str] Switch to STRING_hash macro
Move the whole 'str_to_hashval' logic into the string vtable functions
Modified:
trunk/include/parrot/string_funcs.h
trunk/src/hash.c
trunk/src/pmc/default.pmc
trunk/src/string/api.c
trunk/src/string/encoding/shared.c
trunk/src/string/encoding/shared.h
trunk/src/string/encoding/ucs2.c
trunk/src/string/encoding/ucs4.c
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/include/parrot/string_funcs.h Sat Oct 2 22:26:47 2010 (r49418)
@@ -353,9 +353,9 @@
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
-size_t Parrot_str_to_hashval(PARROT_INTERP, ARGMOD_NULLOK(STRING *s))
+size_t Parrot_str_to_hashval(PARROT_INTERP, ARGIN(const STRING *s))
__attribute__nonnull__(1)
- FUNC_MODIFIES(*s);
+ __attribute__nonnull__(2);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
@@ -595,7 +595,8 @@
#define ASSERT_ARGS_Parrot_str_to_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_to_hashval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_str_to_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_str_to_num __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/hash.c Sat Oct 2 22:26:47 2010 (r49418)
@@ -141,34 +141,11 @@
PARROT_WARN_UNUSED_RESULT
PARROT_PURE_FUNCTION
PARROT_INLINE
-static size_t key_hash_int(SHIM_INTERP,
- ARGIN_NULLOK(const void *value),
- size_t seed);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-PARROT_INLINE
-static size_t key_hash_PMC(PARROT_INTERP,
- ARGIN(PMC *value),
- SHIM(size_t seed))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-PARROT_INLINE
-static size_t key_hash_pointer(SHIM_INTERP,
- ARGIN(const void *value),
+static size_t key_hash_STRING(PARROT_INTERP,
+ ARGIN(const STRING *s),
size_t seed)
- __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-PARROT_INLINE
-static size_t key_hash_STRING(PARROT_INTERP, ARGMOD(STRING *s), size_t seed)
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*s);
+ __attribute__nonnull__(2);
PARROT_CAN_RETURN_NULL
static HashBucket * parrot_hash_get_bucket_string(PARROT_INTERP,
@@ -239,12 +216,6 @@
, PARROT_ASSERT_ARG(hash))
#define ASSERT_ARGS_key_hash_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(value))
-#define ASSERT_ARGS_key_hash_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_key_hash_PMC __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(value))
-#define ASSERT_ARGS_key_hash_pointer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(value))
#define ASSERT_ARGS_key_hash_STRING __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(s))
@@ -270,7 +241,8 @@
/*
-=item C<static size_t key_hash_STRING(PARROT_INTERP, STRING *s, size_t seed)>
+=item C<static size_t key_hash_STRING(PARROT_INTERP, const STRING *s, size_t
+seed)>
Returns the hashed value of the key C<value>. See also string.c.
@@ -283,14 +255,14 @@
PARROT_PURE_FUNCTION
PARROT_INLINE
static size_t
-key_hash_STRING(PARROT_INTERP, ARGMOD(STRING *s), size_t seed)
+key_hash_STRING(PARROT_INTERP, ARGIN(const STRING *s), size_t seed)
{
ASSERT_ARGS(key_hash_STRING)
if (s->hashval)
return s->hashval;
- return Parrot_str_to_hashval(interp, s);
+ return STRING_hash(interp, s, seed);
}
@@ -372,28 +344,6 @@
/*
-=item C<static size_t key_hash_pointer(PARROT_INTERP, const void *value, size_t
-seed)>
-
-Returns a hashvalue for a pointer.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-PARROT_INLINE
-static size_t
-key_hash_pointer(SHIM_INTERP, ARGIN(const void *value), size_t seed)
-{
- ASSERT_ARGS(key_hash_pointer)
- return ((size_t) value) ^ seed;
-}
-
-
-/*
-
=item C<static size_t key_hash_cstring(PARROT_INTERP, const void *value, size_t
seed)>
@@ -450,26 +400,6 @@
/*
-=item C<static size_t key_hash_PMC(PARROT_INTERP, PMC *value, size_t seed)>
-
-Returns a hashed value for an PMC key (passed as a void pointer, sadly).
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-PARROT_INLINE
-static size_t
-key_hash_PMC(PARROT_INTERP, ARGIN(PMC *value), SHIM(size_t seed))
-{
- ASSERT_ARGS(key_hash_PMC)
- return VTABLE_hashvalue(interp, value);
-}
-
-/*
-
=item C<static int hash_compare_pmc(PARROT_INTERP, PMC *a, PMC *b)>
Compares two PMC for equality, returning 0 if the first is equal to second.
@@ -500,27 +430,6 @@
/*
-=item C<static size_t key_hash_int(PARROT_INTERP, const void *value, size_t
-seed)>
-
-Returns a hashed value for an integer key (passed as a void pointer, sadly).
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-PARROT_INLINE
-static size_t
-key_hash_int(SHIM_INTERP, ARGIN_NULLOK(const void *value), size_t seed)
-{
- ASSERT_ARGS(key_hash_int)
- return (size_t)value ^ seed;
-}
-
-/*
-
=item C<static int hash_compare_int(PARROT_INTERP, const void *a, const void
*b)>
Modified: trunk/src/pmc/default.pmc
==============================================================================
--- trunk/src/pmc/default.pmc Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/pmc/default.pmc Sat Oct 2 22:26:47 2010 (r49418)
@@ -797,7 +797,7 @@
INTVAL hashvalue() {
STRING *s = SELF.get_string();
- return Parrot_str_to_hashval(INTERP, s);
+ return STRING_hash(INTERP, s, INTERP->hash_seed);
}
/*
Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/string/api.c Sat Oct 2 22:26:47 2010 (r49418)
@@ -2219,11 +2219,13 @@
/*
-=item C<size_t Parrot_str_to_hashval(PARROT_INTERP, STRING *s)>
+=item C<size_t Parrot_str_to_hashval(PARROT_INTERP, const STRING *s)>
Returns the hash value for the specified Parrot string, caching it in
C<< s->hashval >>.
+Identical to the STRING_hash macro.
+
=cut
*/
@@ -2231,20 +2233,14 @@
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
size_t
-Parrot_str_to_hashval(PARROT_INTERP, ARGMOD_NULLOK(STRING *s))
+Parrot_str_to_hashval(PARROT_INTERP, ARGIN(const STRING *s))
{
ASSERT_ARGS(Parrot_str_to_hashval)
- size_t hashval = interp->hash_seed;
-
- if (!STRING_IS_NULL(s)) {
- if (s->strlen)
- hashval = STRING_hash(interp, s, hashval);
-
- s->hashval = hashval;
- }
+ if (s == NULL)
+ s = STRINGNULL;
- return hashval;
+ return STRING_hash(interp, s, interp->hash_seed);
}
Modified: trunk/src/string/encoding/shared.c
==============================================================================
--- trunk/src/string/encoding/shared.c Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/string/encoding/shared.c Sat Oct 2 22:26:47 2010 (r49418)
@@ -195,7 +195,7 @@
/*
-=item C<size_t encoding_hash(PARROT_INTERP, const STRING *src, size_t seed)>
+=item C<size_t encoding_hash(PARROT_INTERP, const STRING *src, size_t hashval)>
Computes the hash of the given STRING C<src> with starting seed value C<seed>.
@@ -205,20 +205,23 @@
PARROT_WARN_UNUSED_RESULT
size_t
-encoding_hash(PARROT_INTERP, ARGIN(const STRING *src), size_t seed)
+encoding_hash(PARROT_INTERP, ARGIN(const STRING *src), size_t hashval)
{
ASSERT_ARGS(encoding_hash)
+ DECL_CONST_CAST;
+ STRING * const s = PARROT_const_cast(STRING *, src);
String_iter iter;
- size_t hashval = seed;
STRING_ITER_INIT(interp, &iter);
- while (iter.charpos < src->strlen) {
- const UINTVAL c = STRING_iter_get_and_advance(interp, src, &iter);
+ while (iter.charpos < s->strlen) {
+ const UINTVAL c = STRING_iter_get_and_advance(interp, s, &iter);
hashval += hashval << 5;
hashval += c;
}
+ s->hashval = hashval;
+
return hashval;
}
@@ -772,7 +775,7 @@
/*
-=item C<size_t fixed8_hash(PARROT_INTERP, const STRING *s, size_t hashval)>
+=item C<size_t fixed8_hash(PARROT_INTERP, const STRING *src, size_t hashval)>
Returns the hashed value of the string, given a seed in hashval.
@@ -782,17 +785,24 @@
PARROT_WARN_UNUSED_RESULT
size_t
-fixed8_hash(SHIM_INTERP, ARGIN(const STRING *s), size_t hashval)
+fixed8_hash(SHIM_INTERP, ARGIN(const STRING *src), size_t hashval)
{
ASSERT_ARGS(fixed8_hash)
- const unsigned char *pos = (const unsigned char *)s->strstart;
- UINTVAL len = s->strlen;
+ DECL_CONST_CAST;
+ STRING * const s = PARROT_const_cast(STRING *, src);
+ const unsigned char *pos;
+ UINTVAL len;
+
+ pos = (const unsigned char *)s->strstart;
+ len = s->strlen;
while (len--) {
hashval += hashval << 5;
hashval += *(pos++);
}
+ s->hashval = hashval;
+
return hashval;
}
Modified: trunk/src/string/encoding/shared.h
==============================================================================
--- trunk/src/string/encoding/shared.h Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/string/encoding/shared.h Sat Oct 2 22:26:47 2010 (r49418)
@@ -64,7 +64,9 @@
__attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
-size_t encoding_hash(PARROT_INTERP, ARGIN(const STRING *src), size_t seed)
+size_t encoding_hash(PARROT_INTERP,
+ ARGIN(const STRING *src),
+ size_t hashval)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -132,7 +134,7 @@
__attribute__nonnull__(3);
PARROT_WARN_UNUSED_RESULT
-size_t fixed8_hash(SHIM_INTERP, ARGIN(const STRING *s), size_t hashval)
+size_t fixed8_hash(SHIM_INTERP, ARGIN(const STRING *src), size_t hashval)
__attribute__nonnull__(2);
PARROT_WARN_UNUSED_RESULT
@@ -306,7 +308,7 @@
, PARROT_ASSERT_ARG(lhs) \
, PARROT_ASSERT_ARG(rhs))
#define ASSERT_ARGS_fixed8_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(src))
#define ASSERT_ARGS_fixed8_index __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(src) \
Modified: trunk/src/string/encoding/ucs2.c
==============================================================================
--- trunk/src/string/encoding/ucs2.c Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/string/encoding/ucs2.c Sat Oct 2 22:26:47 2010 (r49418)
@@ -36,10 +36,9 @@
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-static size_t ucs2_hash(PARROT_INTERP,
- ARGIN(const STRING *s),
+static size_t ucs2_hash(SHIM_INTERP,
+ ARGIN(const STRING *src),
size_t hashval)
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
static UINTVAL ucs2_iter_get(PARROT_INTERP,
@@ -102,8 +101,7 @@
__attribute__nonnull__(2);
#define ASSERT_ARGS_ucs2_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(src))
#define ASSERT_ARGS_ucs2_iter_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(str) \
@@ -376,7 +374,8 @@
/*
-=item C<static size_t ucs2_hash(PARROT_INTERP, const STRING *s, size_t hashval)>
+=item C<static size_t ucs2_hash(PARROT_INTERP, const STRING *src, size_t
+hashval)>
Returns the hashed value of the string, given a seed in hashval.
@@ -385,27 +384,25 @@
*/
static size_t
-ucs2_hash(PARROT_INTERP, ARGIN(const STRING *s), size_t hashval)
+ucs2_hash(SHIM_INTERP, ARGIN(const STRING *src), size_t hashval)
{
ASSERT_ARGS(ucs2_hash)
-#if PARROT_HAS_ICU
- const UChar *pos = (const UChar*) s->strstart;
- UINTVAL len = s->strlen;
- UNUSED(interp);
+ DECL_CONST_CAST;
+ STRING * const s = PARROT_const_cast(STRING *, src);
+ const Parrot_UInt2 *pos;
+ UINTVAL len;
+
+ pos = (const Parrot_UInt2*)s->strstart;
+ len = s->strlen;
while (len--) {
hashval += hashval << 5;
hashval += *(pos++);
}
- return hashval;
+ s->hashval = hashval;
-#else
- UNUSED(s);
- UNUSED(hashval);
-
- no_ICU_lib(interp);
-#endif
+ return hashval;
}
static STR_VTABLE Parrot_ucs2_encoding = {
Modified: trunk/src/string/encoding/ucs4.c
==============================================================================
--- trunk/src/string/encoding/ucs4.c Sat Oct 2 22:26:13 2010 (r49417)
+++ trunk/src/string/encoding/ucs4.c Sat Oct 2 22:26:47 2010 (r49418)
@@ -36,10 +36,9 @@
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-static size_t ucs4_hash(PARROT_INTERP,
- ARGIN(const STRING *s),
+static size_t ucs4_hash(SHIM_INTERP,
+ ARGIN(const STRING *src),
size_t hashval)
- __attribute__nonnull__(1)
__attribute__nonnull__(2);
static UINTVAL ucs4_iter_get(PARROT_INTERP,
@@ -102,8 +101,7 @@
__attribute__nonnull__(2);
#define ASSERT_ARGS_ucs4_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(s))
+ PARROT_ASSERT_ARG(src))
#define ASSERT_ARGS_ucs4_iter_get __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(str) \
@@ -386,7 +384,8 @@
/*
-=item C<static size_t ucs4_hash(PARROT_INTERP, const STRING *s, size_t hashval)>
+=item C<static size_t ucs4_hash(PARROT_INTERP, const STRING *src, size_t
+hashval)>
Returns the hashed value of the string, given a seed in hashval.
@@ -395,18 +394,24 @@
*/
static size_t
-ucs4_hash(PARROT_INTERP, ARGIN(const STRING *s), size_t hashval)
+ucs4_hash(SHIM_INTERP, ARGIN(const STRING *src), size_t hashval)
{
ASSERT_ARGS(ucs4_hash)
- const Parrot_UInt4 *pos = (const Parrot_UInt4 *) s->strstart;
- UINTVAL len = s->strlen;
- UNUSED(interp);
+ DECL_CONST_CAST;
+ STRING * const s = PARROT_const_cast(STRING *, src);
+ const Parrot_UInt4 *pos;
+ UINTVAL len;
+
+ pos = (const Parrot_UInt4 *)s->strstart;
+ len = s->strlen;
while (len--) {
hashval += hashval << 5;
hashval += *(pos++);
}
+ s->hashval = hashval;
+
return hashval;
}
More information about the parrot-commits
mailing list