Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r70283:18557316383a
Date: 2014-03-25 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/18557316383a/
Log: I think it's preferable to avoid rare conflicts even at the cost of
one additional check for zero-ness during strdict lookups.
diff --git a/rpython/rtyper/lltypesystem/rstr.py
b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -377,17 +377,17 @@
# special non-computed-yet value.
if not s:
return 0
- #with stm_ignored:
- x = s.hash
+ with stm_ignored:
+ x = s.hash
if x == 0:
- x = _hash_string(s.chars)
- if x == 0:
- x = 29872897
- # XXX STM note: we would like this write to be stm-ignored,
- # but we can't, because ll_strfasthash() might later miss
- # the written value and return 0 again (rarely). Think
- # again later about the best option.
- #with stm_ignored:
+ x = LLHelpers._ll_compute_strhash(s)
+ return x
+
+ def _ll_compute_strhash(s):
+ x = _hash_string(s.chars)
+ if x == 0:
+ x = 29872897
+ with stm_ignored:
s.hash = x
return x
@@ -395,7 +395,17 @@
return len(s.chars)
def ll_strfasthash(s):
- return s.hash # assumes that the hash is already computed
+ if rgc.stm_is_enabled():
+ # due to "with stm_ignored" in _ll_strhash(), it is possible
+ # that just returning 's.hash' from here would rarely return
+ # the old value, which is 0. We need to check.
+ with stm_ignored:
+ x = s.hash
+ if x == 0:
+ x = LLHelpers._ll_compute_strhash(s)
+ return x
+ else:
+ return s.hash # assumes that the hash is already computed
@jit.elidable
def ll_strconcat(s1, s2):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit