FixedVector(size, value) should not double-initialize non-POD elements#61560
Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom Mar 29, 2026
Merged
Conversation
Collaborator
|
EWS run on current version of this PR (hash 96cea8f) Details |
weinig
approved these changes
Mar 28, 2026
| @@ -92,10 +92,8 @@ class FixedVector { | |||
| { } | |||
|
|
|||
| FixedVector(size_t size, const T& value) | |||
Contributor
There was a problem hiding this comment.
I'd be tempted to add a FillWith type tag here too, as the constructor without it is always a confusion point for me.
Contributor
Author
There was a problem hiding this comment.
This is a fairly large change I suspect, especially because we'd want to align the similar Vector constructor as well. I will look into doing this separately.
https://bugs.webkit.org/show_bug.cgi?id=310963 Reviewed by Sam Weinig. The `FixedVector(size_t, const T&)` constructor was first default-constructing all elements via `Storage::create(size)`, then copy-assigning over them with `fill(value)`. For non-POD types, this means N default constructions + N copy assignments instead of just N copy constructions. Fix this by adding a `createFilled()` factory to `EmbeddedFixedVector` backed by a new `TrailingArray` FillWith constructor that uses `VectorTypeOperations::uninitializedFill`, matching what `Vector(size, val)` already does. Also add API test coverage for this constructor, which had none. Test: Tools/TestWebKitAPI/Tests/WTF/FixedVector.cpp * Source/WTF/wtf/EmbeddedFixedVector.h: * Source/WTF/wtf/FixedVector.h: (WTF::FixedVector::FixedVector): * Source/WTF/wtf/TrailingArray.h: (WTF::TrailingArray::TrailingArray): * Tools/TestWebKitAPI/Tests/WTF/FixedVector.cpp: (TestWebKitAPI::TEST(WTF_FixedVector, SizeAndValueConstructorPOD)): (TestWebKitAPI::TEST(WTF_FixedVector, SizeAndValueConstructorNonPOD)): (TestWebKitAPI::TEST(WTF_FixedVector, SizeAndValueConstructorZeroSize)): (TestWebKitAPI::TEST(WTF_FixedVector, SizeAndValueConstructorSingleElement)): Canonical link: https://commits.webkit.org/310167@main
96cea8f to
422833b
Compare
Collaborator
|
Committed 310167@main (422833b): https://commits.webkit.org/310167@main Reviewed commits have been landed. Closing PR #61560 and removing active labels. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 ios-apple
422833b
96cea8f