Commit ce788e39 authored by Chris Palmer's avatar Chris Palmer Committed by Commit Bot

Performance-tune the checked math in `StringImpl`.

We regain some microtime by only checking the math in `Release` in DCHECK
builds. In production, don't check.

Bug: 965157
Change-Id: I8a4b84bd2e51bbe26c182d355116ebee2fac9cee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636593Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Chris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664804}
parent 5b1e551c
......@@ -288,8 +288,18 @@ class WTF_EXPORT StringImpl {
DCHECK(IsStatic() || verifier_.OnDeref(ref_count_))
<< AsciiForDebugging() << " " << CurrentThread();
#endif
if (!IsStatic())
if (!IsStatic()) {
#if DCHECK_IS_ON()
// In non-DCHECK builds, we can save a bit of time in micro-benchmarks by
// not checking the arithmetic. We hope that checking in DCHECK builds is
// enough to catch implementation bugs, and that implementation bugs are
// the only way we'd experience underflow.
ref_count_ = base::CheckSub(ref_count_, 1).ValueOrDie();
#else
--ref_count_;
#endif
}
if (ref_count_ == 0)
DestroyIfNotStatic();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment