This CL replaces the deprecated IsPowerOfTwo function with the
std::has_single_bit function from the C++20 standard library.
Bug: 40256225
Change-Id: I7541ab0caad4ae6c14670dd7ad000e42d28edc7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6070097
Commit-Queue: Alex Attar <aattar@google.com>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1392263}
In preparation for the migration to <bit>, require unsigned types, and
use concepts to clean things up. Provide a "deprecated do not use"
version of the functions for code that has yet to be cleaned up.
Bypasses the presubmit because it needs to refer to a banned type
(though it does not use it).
NOPRESUBMIT=true
Bug: 1414634
Change-Id: I5b9ea3c9e9023499669a141d9aa522e0fe21d129
Low-Coverage-Reason: LARGE_SCALE_REFACTOR Renaming and migration of other people’s code
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5041522
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1230243}
Since there are always 8 bits in a byte, just use the value of 8 instead
of the CHAR_BIT constant. CHAR_BIT can potentially be a value other than
8.
Also make the same change to the PartitionAlloc version of
LeftmostBit(), and fix a typo in the unit test for LeftmostBit().
Change-Id: Ic70502feda6288cfa63acb5ae1794b342a39cdeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4649469
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Olivier Li <olivierli@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1163049}
to the new call. The old one is still there, as there are many callers
across the codebase.
bits: :Align() is confusing, and not uniform (the opposite is called
bits: :AlignDown()). Make naming consistent, and convert base/allocator
Change-Id: I7f94e9a41665107c109bc120bca56232d1f5cbd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550796
Commit-Queue: Benoit L <lizeb@chromium.org>
Reviewed-by: Chris Palmer <palmer@chromium.org>
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#849665}
Supports alignment of pointers without forcing users to employ the
casts required to use the existing functions. Enables only for pointers
to 1 byte types (e.g. uint8_t/char) to avoid ambiguity about whether
alignment is measured in bytes or sizeof of the pointed-to type.
Updates code to use the new functions.
Change-Id: If196122876c7e753b3faaa116fdf1874d8cf1db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2300342
Commit-Queue: Mike Wittman <wittman@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Reviewed-by: vmpstr <vmpstr@chromium.org>
Auto-Submit: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792136}
This avoid having to type 1 << (numbits_ - 1) in several places which
can make code harder to read and can be typo prone. This function can
also be used within another template.
Change-Id: I46af3ab832bb58a6565702a391db028b2a69807f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222526
Commit-Queue: Oliver Li <olivierli@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773344}
Currently, base::bits::Count{Leading,Trailing}ZeroBits fail to link
when used with 64-bit inputs on 32-bit MSVC builds because MSVC only
implements the _BitScan{Forward,Reverse}64 intrinsics for 64-bit
builds. Fix this by implementing equivalent support using 32-bit
intrinsics.
Change-Id: I9b9095abd03587c29dd642df65cf9783bd9b202d
Reviewed-on: https://chromium-review.googlesource.com/c/1321253
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607887}
Currently the growth logic of base::Pickle (the one that kicks
in exceeding the current capacity when writing) is as follows:
new_payload_capacity = current_payload_capacity * 2
with an initial payload capacity of 64 bytes.
However, the size of the heap held by Pickle (the one which gets
realloc-ated on each growth) is:
payload_capacity + header_size (typically 4-20 bytes).
In practice, this means that when the Pickle is expanded, the
size of its underlying heap becomes a power of two plus some extra.
This causes funky behaviors of realloc, which makes extremely
difficult to estimate the size of a pickle (for the sake of
memory profiling, Pickle is used to store TracedValue(s)).
This CL adds a small adjustment to the Pickle growth strategy,
making the underlying realloc sizes close to a full page size.
This in turn makes the realloc behavior much more predictable.
As a bonus this CL refactors the use of "Align", moving it to
base/bits.h
BUG=512383
Review URL: https://codereview.chromium.org/1249643007
Cr-Commit-Position: refs/heads/master@{#340318}