Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f4bda74

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Rename SkTArray::reserve to reserve_back.
The semantics of `vector::reserve` and `SkTArray::reserve` were not the same. SkTArray::reserve takes a delta over the current array size, whereas vector takes a total array size. This could lead to subtle errors with over- or under-reservation, hurting performance. This CL renames `SkTArray::reserve` to `SkTArray::reserve_back` to give the SkTArray behavior a distinct (hopefully easily understandable) name, leaving its functionality as-is. Change-Id: Icbd3114bb317fd5f307f393c02ae6fb6f83764e9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326956 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
1 parent 6aaecfb commit f4bda74

32 files changed

+57
-57
lines changed

bench/CreateBackendTextureBench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CreateBackendTextureBench : public Benchmark {
2828
void onDraw(int loops, SkCanvas* canvas) override {
2929
auto context = canvas->recordingContext()->asDirectContext();
3030

31-
fBackendTextures.reserve(loops);
31+
fBackendTextures.reserve_back(loops);
3232

3333
static const int kSize = 16;
3434
for (int i = 0; i < loops; ++i) {

bench/SKPBench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
5757
int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(tileW));
5858
int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(tileH));
5959

60-
fSurfaces.reserve(xTiles * yTiles);
60+
fSurfaces.reserve_back(xTiles * yTiles);
6161
fTileRects.setReserve(xTiles * yTiles);
6262

6363
SkImageInfo ii = canvas->imageInfo().makeWH(tileW, tileH);

include/private/SkTArray.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ template <typename T, bool MEM_MOVE = false> class SkTArray {
162162
/**
163163
* Ensures there is enough reserved space for n additional elements. The is guaranteed at least
164164
* until the array size grows above n and subsequently shrinks below n, any version of reset()
165-
* is called, or reserve() is called again.
165+
* is called, or reserve_back() is called again.
166166
*/
167-
void reserve(int n) {
167+
void reserve_back(int n) {
168168
SkASSERT(n >= 0);
169169
if (n > 0) {
170170
this->checkRealloc(n);

modules/skparagraph/src/ParagraphImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void ParagraphImpl::buildClusterTable() {
308308
fCodeUnitProperties[run.textRange().start] |= CodeUnitFlags::kSoftLineBreakBefore;
309309
fCodeUnitProperties[run.textRange().end] |= CodeUnitFlags::kSoftLineBreakBefore;
310310
} else {
311-
fClusters.reserve(fClusters.size() + run.size());
311+
fClusters.reserve_back(fClusters.size() + run.size());
312312
// Walk through the glyph in the direction of input text
313313
run.iterateThroughClustersInTextOrder([runIndex, this](size_t glyphStart,
314314
size_t glyphEnd,

samplecode/SampleImageFilterDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct FilterNode {
7070
this->computeInputBounds();
7171
this->computeOutputBounds();
7272
if (fFilter) {
73-
fInputNodes.reserve(fFilter->countInputs());
73+
fInputNodes.reserve_back(fFilter->countInputs());
7474
for (int i = 0; i < fFilter->countInputs(); ++i) {
7575
fInputNodes.emplace_back(fFilter->getInput(i), mapping, content, depth + 1);
7676
}

src/core/SkPictureData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
327327
} break;
328328
case SK_PICT_PICTURE_TAG: {
329329
SkASSERT(fPictures.empty());
330-
fPictures.reserve(SkToInt(size));
330+
fPictures.reserve_back(SkToInt(size));
331331

332332
for (uint32_t i = 0; i < size; i++) {
333333
auto pic = SkPicture::MakeFromStream(stream, &procs, topLevelTFPlayback);

src/core/SkTTopoSort.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ bool SkTTopoSort(SkTArray<sk_sp<T>>* graph) {
8686
SkTTopoSort_CheckAllUnmarked<T, Traits>(*graph);
8787
#endif
8888

89-
result.reserve(graph->count());
89+
result.reserve_back(graph->count());
9090

9191
for (int i = 0; i < graph->count(); ++i) {
9292
if (Traits::WasOutput((*graph)[i].get())) {

src/gpu/ccpr/GrCCStrokeGeometry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,12 @@ void GrCCStrokeGeometry::recordCapsIfAny() {
572572

573573
// Reserve the space first, since push_back() takes the point by reference and might
574574
// invalidate the reference if the array grows.
575-
fPoints.reserve(fPoints.count() + 1);
575+
fPoints.reserve_back(fPoints.count() + 1);
576576
fPoints.push_back(fPoints[fCurrContourFirstPtIdx]);
577577

578578
// Reserve the space first, since push_back() takes the normal by reference and might
579579
// invalidate the reference if the array grows. (Although in this case we should be fine
580580
// since there is a negate operator.)
581-
fNormals.reserve(fNormals.count() + 1);
581+
fNormals.reserve_back(fNormals.count() + 1);
582582
fNormals.push_back(-fNormals[fCurrContourFirstNormalIdx]);
583583
}

src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void GrCoverageCountingPathRenderer::preFlush(
246246

247247
// Move the per-opsTask paths that are about to be flushed from fPendingPaths to fFlushingPaths,
248248
// and count them up so we can preallocate buffers.
249-
fFlushingPaths.reserve(numOpsTaskIDs);
249+
fFlushingPaths.reserve_back(numOpsTaskIDs);
250250
for (int i = 0; i < numOpsTaskIDs; ++i) {
251251
auto iter = fPendingPaths.find(opsTaskIDs[i]);
252252
if (fPendingPaths.end() == iter) {

src/gpu/gradients/GrGradientShader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static std::unique_ptr<GrFragmentProcessor> make_gradient(const SkGradientShader
185185
if (shader.fOrigPos) {
186186
positions = shader.fOrigPos;
187187
} else {
188-
implicitPos.reserve(shader.fColorCount);
188+
implicitPos.reserve_back(shader.fColorCount);
189189
SkScalar posScale = SK_Scalar1 / (shader.fColorCount - 1);
190190
for (int i = 0 ; i < shader.fColorCount; i++) {
191191
implicitPos.push_back(SkIntToScalar(i) * posScale);

0 commit comments

Comments
 (0)