Skip to content

Commit 29e1542

Browse files
committed
Bulk-convert a lot of "&x[0]" to the "x.data()" form
Most of them done programmatically with something like: perl -pi -e 's/\&pts\[0\]/pts.data()/g' skia/* Copilot points out that the latter is safer. Many(all?) of them were touched by the recent SkSpan changes, plus a few more.
1 parent 8d73e07 commit 29e1542

7 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/skia/Canvas.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ canvas
13461346
// &SkCanvas::drawPoints,
13471347
[] (SkCanvas& canvas, SkCanvas::PointMode mode,
13481348
const std::vector<SkPoint>& points, const SkPaint &paint) {
1349-
canvas.drawPoints(mode, {&points[0], points.size()}, paint);
1349+
canvas.drawPoints(mode, {points.data(), points.size()}, paint);
13501350
},
13511351
R"docstring(
13521352
Draws pts using clip, :py:class:`Matrix` and :py:class:`Paint`
@@ -2318,8 +2318,8 @@ canvas
23182318
if (!colors.empty() && colors.size() != xform.size())
23192319
throw std::runtime_error(
23202320
"colors must have the same length with xform.");
2321-
canvas.drawAtlas(atlas, {&xform[0], xform.size()}, {&tex[0], tex.size()},
2322-
{(colors.empty()) ? nullptr : &colors[0],
2321+
canvas.drawAtlas(atlas, {xform.data(), xform.size()}, {tex.data(), tex.size()},
2322+
{(colors.empty()) ? nullptr : colors.data(),
23232323
colors.size()}, mode, options, cullRect, paint);
23242324
},
23252325
R"docstring(

src/skia/Font.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ typeface
524524
.def("unicharsToGlyphs",
525525
[] (const SkTypeface& typeface, const std::vector<SkUnichar>& chars) {
526526
std::vector<SkGlyphID> glyphs(chars.size());
527-
typeface.unicharsToGlyphs({&chars[0], chars.size()}, {&glyphs[0], glyphs.size()});
527+
typeface.unicharsToGlyphs({chars.data(), chars.size()}, {glyphs.data(), glyphs.size()});
528528
return glyphs;
529529
},
530530
R"docstring(
@@ -556,7 +556,7 @@ typeface
556556
.def("getTableTags",
557557
[] (const SkTypeface& typeface) {
558558
std::vector<SkFontTableTag> tags(typeface.countTables());
559-
size_t size = typeface.readTableTags({&tags[0], tags.size()});
559+
size_t size = typeface.readTableTags({tags.data(), tags.size()});
560560
if (size < tags.size())
561561
throw std::runtime_error("Failed to get table tags.");
562562
return tags;
@@ -613,7 +613,7 @@ typeface
613613
const std::vector<SkGlyphID>& glyphs) -> py::object {
614614
std::vector<int32_t> adjustments(glyphs.size() - 1);
615615
auto result = typeface.getKerningPairAdjustments(
616-
{&glyphs[0], glyphs.size()}, {(glyphs.size() > 1) ? &adjustments[0] : nullptr, adjustments.size()});
616+
{glyphs.data(), glyphs.size()}, {(glyphs.size() > 1) ? adjustments.data() : nullptr, adjustments.size()});
617617
if (!result) {
618618
// Kerning is not supported for this typeface.
619619
return py::none();
@@ -1312,10 +1312,10 @@ font
13121312
.def("textToGlyphs",
13131313
[] (const SkFont& font, const std::string& text,
13141314
SkTextEncoding encoding) {
1315-
int count = font.countText(&text[0], text.size(), encoding);
1315+
int count = font.countText(text.data(), text.size(), encoding);
13161316
std::vector<SkGlyphID> glyphs(count);
13171317
font.textToGlyphs(
1318-
&text[0], text.size(), encoding, {&glyphs[0], glyphs.size()});
1318+
text.data(), text.size(), encoding, {glyphs.data(), glyphs.size()});
13191319
return glyphs;
13201320
},
13211321
R"docstring(
@@ -1355,14 +1355,14 @@ font
13551355
.def("unicharsToGlyphs",
13561356
[] (const SkFont& font, const std::vector<SkUnichar>& uni) {
13571357
std::vector<SkGlyphID> glyphs(uni.size());
1358-
font.unicharsToGlyphs({&uni[0], uni.size()}, {&glyphs[0], glyphs.size()});
1358+
font.unicharsToGlyphs({uni.data(), uni.size()}, {glyphs.data(), glyphs.size()});
13591359
return glyphs;
13601360
},
13611361
py::arg("uni"))
13621362
.def("countText",
13631363
[] (const SkFont& font, const std::string& text,
13641364
SkTextEncoding encoding) {
1365-
return font.countText(&text[0], text.size(), encoding);
1365+
return font.countText(text.data(), text.size(), encoding);
13661366
},
13671367
R"docstring(
13681368
Returns number of glyphs represented by text.
@@ -1380,7 +1380,7 @@ font
13801380
[] (const SkFont& font, const std::string& text,
13811381
SkTextEncoding encoding, SkRect* bounds, const SkPaint* paint) {
13821382
return font.measureText(
1383-
&text[0], text.size(), encoding, bounds, paint);
1383+
text.data(), text.size(), encoding, bounds, paint);
13841384
},
13851385
R"docstring(
13861386
Returns the advance width of text.
@@ -1402,7 +1402,7 @@ font
14021402
.def("getWidths",
14031403
[] (const SkFont& font, const std::vector<SkGlyphID>& glyphs) {
14041404
std::vector<SkScalar> width(glyphs.size());
1405-
font.getWidths({&glyphs[0], glyphs.size()}, {&width[0], width.size()});
1405+
font.getWidths({glyphs.data(), glyphs.size()}, {width.data(), width.size()});
14061406
return width;
14071407
},
14081408
R"docstring(
@@ -1418,7 +1418,7 @@ font
14181418
std::vector<SkScalar> width(glyphs.size());
14191419
std::vector<SkRect> bounds(glyphs.size());
14201420
font.getWidthsBounds(
1421-
{&glyphs[0], glyphs.size()}, {&width[0], width.size()}, {&bounds[0], bounds.size()}, paint);
1421+
{glyphs.data(), glyphs.size()}, {width.data(), width.size()}, {bounds.data(), bounds.size()}, paint);
14221422
return py::make_tuple(width, bounds);
14231423
},
14241424
R"docstring(
@@ -1435,7 +1435,7 @@ font
14351435
[] (const SkFont& font, const std::vector<SkGlyphID>& glyphs,
14361436
const SkPaint* paint) {
14371437
std::vector<SkRect> bounds(glyphs.size());
1438-
font.getBounds({&glyphs[0], glyphs.size()}, {&bounds[0], bounds.size()}, paint);
1438+
font.getBounds({glyphs.data(), glyphs.size()}, {bounds.data(), bounds.size()}, paint);
14391439
return bounds;
14401440
},
14411441
R"docstring(
@@ -1455,7 +1455,7 @@ font
14551455
[] (const SkFont& font, const std::vector<SkGlyphID>& glyphs,
14561456
const SkPoint& origin) {
14571457
std::vector<SkPoint> pos(glyphs.size());
1458-
font.getPos({&glyphs[0], glyphs.size()}, {&pos[0], pos.size()}, origin);
1458+
font.getPos({glyphs.data(), glyphs.size()}, {pos.data(), pos.size()}, origin);
14591459
return pos;
14601460
},
14611461
R"docstring(
@@ -1473,7 +1473,7 @@ font
14731473
[] (const SkFont& font, const std::vector<SkGlyphID>& glyphs,
14741474
const SkScalar& origin) {
14751475
std::vector<SkScalar> xpos(glyphs.size());
1476-
font.getXPos({&glyphs[0], glyphs.size()}, {&xpos[0], xpos.size()}, origin);
1476+
font.getXPos({glyphs.data(), glyphs.size()}, {xpos.data(), xpos.size()}, origin);
14771477
return xpos;
14781478
},
14791479
R"docstring(

src/skia/Matrix.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ matrix
12011201
throw std::runtime_error("src and dst must have the same size");
12021202
if (src.empty())
12031203
return matrix.setPolyToPoly({nullptr, 0}, {nullptr, 0});
1204-
return matrix.setPolyToPoly({&src[0], src.size()}, {&dst[0], dst.size()});
1204+
return matrix.setPolyToPoly({src.data(), src.size()}, {dst.data(), dst.size()});
12051205
},
12061206
R"docstring(
12071207
Sets :py:class:`Matrix` to map src to dst.
@@ -1294,7 +1294,7 @@ matrix
12941294
[] (const SkMatrix& matrix, std::vector<SkPoint>& pts) {
12951295
if (pts.empty())
12961296
return pts;
1297-
matrix.mapPoints({&pts[0], pts.size()}, {&pts[0], pts.size()});
1297+
matrix.mapPoints({pts.data(), pts.size()}, {pts.data(), pts.size()});
12981298
return pts;
12991299
},
13001300
R"docstring(
@@ -1328,7 +1328,7 @@ matrix
13281328
[] (const SkMatrix& matrix, std::vector<SkPoint3>& pts) -> py::object {
13291329
if (pts.empty())
13301330
return py::cast(pts);
1331-
matrix.mapHomogeneousPoints({&pts[0], pts.size()}, {&pts[0], pts.size()});
1331+
matrix.mapHomogeneousPoints({pts.data(), pts.size()}, {pts.data(), pts.size()});
13321332
return py::cast(pts);
13331333
},
13341334
R"docstring(
@@ -1357,7 +1357,7 @@ matrix
13571357
if (pts.empty())
13581358
return py::cast(pts);
13591359
std::vector<SkPoint3> dst(pts.size());
1360-
matrix.mapPointsToHomogeneous({&dst[0], dst.size()}, {&pts[0], pts.size()});
1360+
matrix.mapPointsToHomogeneous({dst.data(), dst.size()}, {pts.data(), pts.size()});
13611361
return py::cast(dst);
13621362
},
13631363
R"docstring(
@@ -1395,7 +1395,7 @@ matrix
13951395
[] (const SkMatrix& matrix, std::vector<SkVector>& src) {
13961396
if (src.empty())
13971397
return src;
1398-
matrix.mapVectors({&src[0], src.size()}, {&src[0], src.size()});
1398+
matrix.mapVectors({src.data(), src.size()}, {src.data(), src.size()});
13991399
return src;
14001400
},
14011401
R"docstring(

src/skia/Path.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ path
712712
if (max == 0)
713713
max = path.countVerbs();
714714
std::vector<SkPoint> points(max);
715-
auto length = path.getPoints({&points[0], max});
715+
auto length = path.getPoints({points.data(), max});
716716
if (length < max)
717717
points.erase(points.begin() + length, points.end());
718718
return points;
@@ -743,7 +743,7 @@ path
743743
if (max == 0)
744744
max = path.countVerbs();
745745
std::vector<uint8_t> verbs(max);
746-
auto length = path.getVerbs({&verbs[0], max});
746+
auto length = path.getVerbs({verbs.data(), max});
747747
if (length < max)
748748
verbs.erase(verbs.begin() + length, verbs.end());
749749
std::vector<SkPath::Verb> verbs_(verbs.size());
@@ -1606,7 +1606,7 @@ path
16061606
<< " elements).";
16071607
throw py::value_error(stream.str());
16081608
}
1609-
return path.addRoundRect(rect, {&radii_[0], radii_.size()}, dir);
1609+
return path.addRoundRect(rect, {radii_.data(), radii_.size()}, dir);
16101610
},
16111611
R"docstring(
16121612
Appends :py:class:`RRect` to :py:class:`Path`, creating a new closed
@@ -1660,7 +1660,7 @@ path
16601660
py::arg("rrect"), py::arg("dir"), py::arg("start"))
16611661
.def("addPoly",
16621662
[] (SkPath& path, const std::vector<SkPoint>& pts, bool close) {
1663-
return path.addPoly({&pts[0], pts.size()}, close);
1663+
return path.addPoly({pts.data(), pts.size()}, close);
16641664
},
16651665
R"docstring(
16661666
Adds contour created from pts.
@@ -2035,7 +2035,7 @@ path
20352035
SkScalar w, int pow2) {
20362036
auto size = (1 + 2 * (1 << pow2));
20372037
std::vector<SkPoint> pts(size);
2038-
SkPath::ConvertConicToQuads(p0, p1, p2, w, &pts[0], pow2);
2038+
SkPath::ConvertConicToQuads(p0, p1, p2, w, pts.data(), pow2);
20392039
// TODO: Shall we return the return value?
20402040
return pts;
20412041
},

src/skia/PathEffect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ py::class_<SkDashPathEffect>(m, "DashPathEffect")
335335
.def_static("Make",
336336
[] (const std::vector<SkScalar>& intervals, SkScalar phase) {
337337
return SkDashPathEffect::Make(
338-
{&intervals[0], intervals.size()}, phase);
338+
{intervals.data(), intervals.size()}, phase);
339339
},
340340
R"docstring(
341341
For example: if intervals[] = {10, 20}, count = 2, and phase = 25, this

src/skia/Rect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ py::class_<SkRect>(m, "Rect", R"docstring(
868868
py::arg("left"), py::arg("top"), py::arg("right"), py::arg("bottom"))
869869
.def("setBounds",
870870
[] (SkRect& rect, const std::vector<SkPoint>& points) {
871-
rect.setBounds({&points[0], points.size()});
871+
rect.setBounds({points.data(), points.size()});
872872
},
873873
R"docstring(
874874
Sets to bounds of :py:class:`Point` array with count entries.
@@ -884,7 +884,7 @@ py::class_<SkRect>(m, "Rect", R"docstring(
884884
py::arg("points"))
885885
.def("setBoundsCheck",
886886
[] (SkRect& rect, const std::vector<SkPoint>& points) {
887-
return rect.setBoundsCheck({&points[0], points.size()});
887+
return rect.setBoundsCheck({points.data(), points.size()});
888888
},
889889
R"docstring(
890890
Sets to bounds of :py:class:`Point` array with count entries.
@@ -902,7 +902,7 @@ py::class_<SkRect>(m, "Rect", R"docstring(
902902
py::arg("points"))
903903
.def("setBoundsNoCheck",
904904
[] (SkRect& rect, const std::vector<SkPoint>& points) {
905-
rect.setBoundsNoCheck({&points[0], points.size()});
905+
rect.setBoundsNoCheck({points.data(), points.size()});
906906
},
907907
R"docstring(
908908
Sets to bounds of :py:class:`Point` pts array with count entries.

src/skia/TextBlob.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ textblob
9494
"len(text) = {} does not match len(pos) = {}").format(
9595
count, pos_.size()));
9696
return SkTextBlob::MakeFromPosText(
97-
text.c_str(), text.size(), {&pos_[0], pos_.size()}, font, encoding);
97+
text.c_str(), text.size(), {pos_.data(), pos_.size()}, font, encoding);
9898
}),
9999
R"docstring(
100100
Creates :py:class:`TextBlob` with a single run.
@@ -286,7 +286,7 @@ textblob
286286
throw py::value_error(stream.str());
287287
}
288288
return SkTextBlob::MakeFromPosTextH(
289-
text.c_str(), text.size(), {&xpos_[0], xpos_.size()}, constY, font, encoding);
289+
text.c_str(), text.size(), {xpos_.data(), xpos_.size()}, constY, font, encoding);
290290
},
291291
R"docstring(
292292
Returns a textblob built from a single run of text with x-positions and
@@ -316,7 +316,7 @@ textblob
316316
throw std::runtime_error(
317317
"text and pos must have the same number of elements.");
318318
return SkTextBlob::MakeFromPosText(
319-
text.c_str(), text.size(), {&pos[0], pos.size()}, font, encoding);
319+
text.c_str(), text.size(), {pos.data(), pos.size()}, font, encoding);
320320
},
321321
R"docstring(
322322
Returns a textblob built from a single run of text with x-positions and
@@ -344,7 +344,7 @@ textblob
344344
throw std::runtime_error(
345345
"text and xform must have the same number of elements.");
346346
return SkTextBlob::MakeFromRSXform(
347-
text.c_str(), text.size(), {&xform[0], xform.size()}, font, encoding);
347+
text.c_str(), text.size(), {xform.data(), xform.size()}, font, encoding);
348348
},
349349
py::arg("text"), py::arg("xform"), py::arg("font"),
350350
py::arg_v("encoding", SkTextEncoding::kUTF8, "skia.TextEncoding.kUTF8"))

0 commit comments

Comments
 (0)