From f838f6f62f62012c2b7d78f41901e4fdcfc21181 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Thu, 16 Jun 2022 14:50:33 -0400 Subject: [PATCH] Replace SK_ARRAY_COUNT with std::size() all the rest Added changes to IWYU_mapping.imp to allow std::size. This requires multiple entries because std::size can be defined from any number of files. Please see the following for reference: https://en.cppreference.com/w/cpp/iterator/size Please check that I got all the includes from the documented list. Change-Id: I8346834ea7f37128f2dc50f238af0665a1fcfd8d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/550696 Reviewed-by: John Stiles Reviewed-by: Kevin Lubick Commit-Queue: Herb Derby --- dm/DM.cpp | 2 +- dm/DMSrcSink.cpp | 2 +- fuzz/FuzzCanvas.cpp | 18 +++++++++--------- fuzz/FuzzParsePath.cpp | 4 ++-- src/c/sk_c_from_to.h | 4 ++-- src/c/sk_effects.cpp | 4 ++-- src/c/sk_imageinfo.cpp | 8 ++++---- src/c/sk_surface.cpp | 4 ++-- .../imagefilters/SkLightingImageFilter.cpp | 12 ++++++------ .../GrGaussianConvolutionFragmentProcessor.h | 2 +- src/opts/SkVM_opts.h | 4 ++-- src/pathops/SkIntersections.cpp | 2 +- src/pathops/SkIntersections.h | 2 +- src/pathops/SkOpEdgeBuilder.cpp | 10 +++++----- src/pathops/SkPathOpsDebug.cpp | 6 +++--- src/pathops/SkPathOpsTSect.cpp | 4 ++-- src/pdf/SkPDFBitmap.cpp | 6 +++--- src/pdf/SkPDFResourceDict.cpp | 6 +++--- src/ports/SkFontConfigInterface_direct.cpp | 8 ++++---- src/ports/SkFontHost_FreeType.cpp | 2 +- src/ports/SkFontHost_win.cpp | 8 ++++---- src/ports/SkFontMgr_android.cpp | 2 +- src/ports/SkFontMgr_custom.cpp | 2 +- src/ports/SkFontMgr_fontconfig.cpp | 16 ++++++++-------- src/ports/SkFontMgr_mac_ct.cpp | 2 +- src/ports/SkTypeface_mac_ct.cpp | 10 +++++----- src/sfnt/SkOTTable_name.cpp | 2 +- src/sfnt/SkOTUtils.cpp | 2 +- src/shaders/SkPerlinNoiseShader.cpp | 4 ++-- src/sksl/SkSLMangler.cpp | 2 +- src/sksl/codegen/SkSLVMCodeGenerator.cpp | 10 +++++----- src/sksl/ir/SkSLFunctionCall.cpp | 2 +- src/sksl/ir/SkSLFunctionDeclaration.cpp | 2 +- src/sksl/tracing/SkVMDebugTrace.cpp | 6 +++--- src/svg/SkSVGDevice.cpp | 8 ++++---- src/utils/SkDashPath.cpp | 3 ++- src/utils/SkJSON.cpp | 2 +- src/utils/SkParse.cpp | 5 +++-- src/utils/mac/SkCTFont.cpp | 6 +++--- src/utils/win/SkWGL_win.cpp | 4 ++-- src/xml/SkXMLParser.cpp | 2 +- src/xml/SkXMLWriter.cpp | 2 +- src/xps/SkXPSDevice.cpp | 14 +++++++------- toolchain/linux_trampolines/IWYU_mapping.imp | 14 ++++++++++++++ 44 files changed, 128 insertions(+), 112 deletions(-) diff --git a/dm/DM.cpp b/dm/DM.cpp index 71181a39a5..e088f9960e 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -371,7 +371,7 @@ static void find_culprit() { #if !defined(SK_BUILD_FOR_ANDROID) void* stack[128]; - int count = backtrace(stack, SK_ARRAY_COUNT(stack)); + int count = backtrace(stack, std::size(stack)); char** symbols = backtrace_symbols(stack, count); info("\nStack trace:\n"); for (int i = 0; i < count; i++) { diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 99d0e3db75..d79bd9a50f 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1261,7 +1261,7 @@ Result SkottieSrc::draw(GrDirectContext*, SkCanvas* canvas) const { // frame progression. The film strip will still be in order left-to-right, // top-down, just not drawn in that order. static constexpr int frameOrder[] = { 4, 0, 3, 1, 2 }; - static_assert(SK_ARRAY_COUNT(frameOrder) == kTileCount, ""); + static_assert(std::size(frameOrder) == kTileCount, ""); for (int i = 0; i < kTileCount; ++i) { const SkScalar y = frameOrder[i] * kTileSize; diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index 69af03dcbb..252f17a9d2 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -110,7 +110,7 @@ static sk_sp make_fuzz_colorfilter(Fuzz* fuzz, int depth) { } case 3: { float array[20]; - fuzz->nextN(array, SK_ARRAY_COUNT(array)); + fuzz->nextN(array, std::size(array)); return SkColorFilters::Matrix(array); } case 4: { @@ -132,7 +132,7 @@ static sk_sp make_fuzz_colorfilter(Fuzz* fuzz, int depth) { return SkLumaColorFilter::Make(); case 7: { uint8_t table[256]; - fuzz->nextN(table, SK_ARRAY_COUNT(table)); + fuzz->nextN(table, std::size(table)); return SkTableColorFilter::Make(table); } case 8: { @@ -140,10 +140,10 @@ static sk_sp make_fuzz_colorfilter(Fuzz* fuzz, int depth) { uint8_t tableR[256]; uint8_t tableG[256]; uint8_t tableB[256]; - fuzz->nextN(tableA, SK_ARRAY_COUNT(tableA)); - fuzz->nextN(tableR, SK_ARRAY_COUNT(tableR)); - fuzz->nextN(tableG, SK_ARRAY_COUNT(tableG)); - fuzz->nextN(tableB, SK_ARRAY_COUNT(tableB)); + fuzz->nextN(tableA, std::size(tableA)); + fuzz->nextN(tableR, std::size(tableR)); + fuzz->nextN(tableG, std::size(tableG)); + fuzz->nextN(tableB, std::size(tableB)); return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB); } default: @@ -395,7 +395,7 @@ static sk_sp make_fuzz_patheffect(Fuzz* fuzz, int depth) { fuzz->next(&phase); SkScalar intervals[20]; int count; - fuzz->nextRange(&count, 0, (int)SK_ARRAY_COUNT(intervals)); + fuzz->nextRange(&count, 0, (int)std::size(intervals)); fuzz->nextN(intervals, count); return SkDashPathEffect::Make(intervals, count, phase); } @@ -900,7 +900,7 @@ static SkTDArray make_fuzz_text(Fuzz* fuzz, const SkFont& font, SkTextE {0x0400, 0x0500}, }; int32_t count = 0; - for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) { + for (size_t i = 0; i < std::size(ranges); ++i) { count += (ranges[i][1] - ranges[i][0]); } constexpr int kMaxLength = kMaxGlyphCount; @@ -910,7 +910,7 @@ static SkTDArray make_fuzz_text(Fuzz* fuzz, const SkFont& font, SkTextE for (int j = 0; j < length; ++j) { int32_t value; fuzz->nextRange(&value, 0, count - 1); - for (size_t i = 0; i < SK_ARRAY_COUNT(ranges); ++i) { + for (size_t i = 0; i < std::size(ranges); ++i) { if (value + ranges[i][0] < ranges[i][1]) { buffer[j] = value + ranges[i][0]; break; diff --git a/fuzz/FuzzParsePath.cpp b/fuzz/FuzzParsePath.cpp index 5ec75d63f0..ce804174fb 100644 --- a/fuzz/FuzzParsePath.cpp +++ b/fuzz/FuzzParsePath.cpp @@ -46,7 +46,7 @@ static void add_white(Fuzz* fuzz, SkString* atom) { fuzz->nextRange(&reps, 0, 2); for (uint8_t rep = 0; rep < reps; ++rep) { uint8_t index; - fuzz->nextRange(&index, 0, (int) SK_ARRAY_COUNT(gWhiteSpace) - 1); + fuzz->nextRange(&index, 0, (int) std::size(gWhiteSpace) - 1); if (gWhiteSpace[index]) { atom->append(&gWhiteSpace[index], 1); } @@ -76,7 +76,7 @@ static void add_comma(Fuzz* fuzz, SkString* atom) { SkString MakeRandomParsePathPiece(Fuzz* fuzz) { SkString atom; uint8_t legalIndex; - fuzz->nextRange(&legalIndex, 0, (int) SK_ARRAY_COUNT(gLegal) - 1); + fuzz->nextRange(&legalIndex, 0, (int) std::size(gLegal) - 1); const Legal& legal = gLegal[legalIndex]; gEasy ? atom.append("\n") : add_white(fuzz, &atom); bool b; diff --git a/src/c/sk_c_from_to.h b/src/c/sk_c_from_to.h index 19fda37a26..d7856199fc 100644 --- a/src/c/sk_c_from_to.h +++ b/src/c/sk_c_from_to.h @@ -6,7 +6,7 @@ */ static bool find_sk(CType from, SKType* to) { - for (size_t i = 0; i < SK_ARRAY_COUNT(CTypeSkTypeMap); ++i) { + for (size_t i = 0; i < std::size(CTypeSkTypeMap); ++i) { if (CTypeSkTypeMap[i].fC == from) { if (to) { *to = CTypeSkTypeMap[i].fSK; @@ -18,7 +18,7 @@ static bool find_sk(CType from, SKType* to) { } static bool find_c(SKType from, CType* to) { - for (size_t i = 0; i < SK_ARRAY_COUNT(CTypeSkTypeMap); ++i) { + for (size_t i = 0; i < std::size(CTypeSkTypeMap); ++i) { if (CTypeSkTypeMap[i].fSK == from) { if (to) { *to = CTypeSkTypeMap[i].fC; diff --git a/src/c/sk_effects.cpp b/src/c/sk_effects.cpp index 7e226cd756..2ce034a458 100644 --- a/src/c/sk_effects.cpp +++ b/src/c/sk_effects.cpp @@ -27,7 +27,7 @@ const struct { }; static bool from_c_tilemode(sk_shader_tilemode_t cMode, SkTileMode* skMode) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gTileModeMap); ++i) { + for (size_t i = 0; i < std::size(gTileModeMap); ++i) { if (cMode == gTileModeMap[i].fC) { if (skMode) { *skMode = gTileModeMap[i].fSK; @@ -158,7 +158,7 @@ const struct { }; static bool find_blurstyle(sk_blurstyle_t csrc, SkBlurStyle* dst) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gBlurStylePairs); ++i) { + for (size_t i = 0; i < std::size(gBlurStylePairs); ++i) { if (gBlurStylePairs[i].fC == csrc) { if (dst) { *dst = gBlurStylePairs[i].fSk; diff --git a/src/c/sk_imageinfo.cpp b/src/c/sk_imageinfo.cpp index 160c7f9ab7..7c341e1b7c 100644 --- a/src/c/sk_imageinfo.cpp +++ b/src/c/sk_imageinfo.cpp @@ -34,7 +34,7 @@ const struct { }; static bool from_c_colortype(sk_colortype_t cCT, SkColorType* skCT) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypeMap); ++i) { + for (size_t i = 0; i < std::size(gColorTypeMap); ++i) { if (gColorTypeMap[i].fC == cCT) { if (skCT) { *skCT = gColorTypeMap[i].fSK; @@ -46,7 +46,7 @@ static bool from_c_colortype(sk_colortype_t cCT, SkColorType* skCT) { } static bool to_c_colortype(SkColorType skCT, sk_colortype_t* cCT) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypeMap); ++i) { + for (size_t i = 0; i < std::size(gColorTypeMap); ++i) { if (gColorTypeMap[i].fSK == skCT) { if (cCT) { *cCT = gColorTypeMap[i].fC; @@ -58,7 +58,7 @@ static bool to_c_colortype(SkColorType skCT, sk_colortype_t* cCT) { } static bool from_c_alphatype(sk_alphatype_t cAT, SkAlphaType* skAT) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gAlphaTypeMap); ++i) { + for (size_t i = 0; i < std::size(gAlphaTypeMap); ++i) { if (gAlphaTypeMap[i].fC == cAT) { if (skAT) { *skAT = gAlphaTypeMap[i].fSK; @@ -70,7 +70,7 @@ static bool from_c_alphatype(sk_alphatype_t cAT, SkAlphaType* skAT) { } static bool to_c_alphatype(SkAlphaType skAT, sk_alphatype_t* cAT) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gAlphaTypeMap); ++i) { + for (size_t i = 0; i < std::size(gAlphaTypeMap); ++i) { if (gAlphaTypeMap[i].fSK == skAT) { if (cAT) { *cAT = gAlphaTypeMap[i].fC; diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp index ca23a7d7ee..cd71578e3b 100644 --- a/src/c/sk_surface.cpp +++ b/src/c/sk_surface.cpp @@ -37,7 +37,7 @@ const struct { static bool from_c_pixelgeometry(sk_pixelgeometry_t cGeom, SkPixelGeometry* skGeom) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gPixelGeometryMap); ++i) { + for (size_t i = 0; i < std::size(gPixelGeometryMap); ++i) { if (gPixelGeometryMap[i].fC == cGeom) { if (skGeom) { *skGeom = gPixelGeometryMap[i].fSK; @@ -63,7 +63,7 @@ const struct { }; static bool from_c_path_direction(sk_path_direction_t cdir, SkPathDirection* dir) { - for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) { + for (size_t i = 0; i < std::size(gPathDirMap); ++i) { if (gPathDirMap[i].fC == cdir) { if (dir) { *dir = gPathDirMap[i].fSk; diff --git a/src/effects/imagefilters/SkLightingImageFilter.cpp b/src/effects/imagefilters/SkLightingImageFilter.cpp index d46538fa30..548041b31f 100644 --- a/src/effects/imagefilters/SkLightingImageFilter.cpp +++ b/src/effects/imagefilters/SkLightingImageFilter.cpp @@ -1785,7 +1785,7 @@ void LightingEffect::ImplBase::emitCode(EmitArgs& args) { SkString sobelFuncName = fragBuilder->getMangledFunctionName("sobel"); fragBuilder->emitFunction(SkSLType::kHalf, sobelFuncName.c_str(), - {gSobelArgs, SK_ARRAY_COUNT(gSobelArgs)}, + {gSobelArgs, std::size(gSobelArgs)}, "return (-a + b - 2.0 * c + 2.0 * d -e + f) * scale;"); const GrShaderVar gPointToNormalArgs[] = { GrShaderVar("x", SkSLType::kHalf), @@ -1795,7 +1795,7 @@ void LightingEffect::ImplBase::emitCode(EmitArgs& args) { SkString pointToNormalName = fragBuilder->getMangledFunctionName("pointToNormal"); fragBuilder->emitFunction(SkSLType::kHalf3, pointToNormalName.c_str(), - {gPointToNormalArgs, SK_ARRAY_COUNT(gPointToNormalArgs)}, + {gPointToNormalArgs, std::size(gPointToNormalArgs)}, "return normalize(half3(-x * scale, -y * scale, 1));"); const GrShaderVar gInteriorNormalArgs[] = { @@ -1808,7 +1808,7 @@ void LightingEffect::ImplBase::emitCode(EmitArgs& args) { SkString normalName = fragBuilder->getMangledFunctionName("normal"); fragBuilder->emitFunction(SkSLType::kHalf3, normalName.c_str(), - {gInteriorNormalArgs, SK_ARRAY_COUNT(gInteriorNormalArgs)}, + {gInteriorNormalArgs, std::size(gInteriorNormalArgs)}, normalBody.c_str()); fragBuilder->codeAppendf("float2 coord = %s;", args.fSampleCoord); @@ -1872,7 +1872,7 @@ void DiffuseLightingEffect::Impl::emitLightFunc(const GrFragmentProcessor* owner *funcName = fragBuilder->getMangledFunctionName("light"); fragBuilder->emitFunction(SkSLType::kHalf4, funcName->c_str(), - {gLightArgs, SK_ARRAY_COUNT(gLightArgs)}, + {gLightArgs, std::size(gLightArgs)}, lightBody.c_str()); } @@ -1979,7 +1979,7 @@ void SpecularLightingEffect::Impl::emitLightFunc(const GrFragmentProcessor* owne *funcName = fragBuilder->getMangledFunctionName("light"); fragBuilder->emitFunction(SkSLType::kHalf4, funcName->c_str(), - {gLightArgs, SK_ARRAY_COUNT(gLightArgs)}, + {gLightArgs, std::size(gLightArgs)}, lightBody.c_str()); } @@ -2119,7 +2119,7 @@ void GpuSpotLight::emitLightColor(const GrFragmentProcessor* owner, fLightColorFunc = fragBuilder->getMangledFunctionName("lightColor"); fragBuilder->emitFunction(SkSLType::kHalf3, fLightColorFunc.c_str(), - {gLightColorArgs, SK_ARRAY_COUNT(gLightColorArgs)}, + {gLightColorArgs, std::size(gLightColorArgs)}, lightColorBody.c_str()); fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); diff --git a/src/gpu/ganesh/effects/GrGaussianConvolutionFragmentProcessor.h b/src/gpu/ganesh/effects/GrGaussianConvolutionFragmentProcessor.h index ffbd717fd7..8fe4c07ce5 100644 --- a/src/gpu/ganesh/effects/GrGaussianConvolutionFragmentProcessor.h +++ b/src/gpu/ganesh/effects/GrGaussianConvolutionFragmentProcessor.h @@ -77,7 +77,7 @@ private: GR_DECLARE_FRAGMENT_PROCESSOR_TEST - inline static constexpr int kMaxKernelWidth = kMaxKernelRadius + 1; + inline static const constexpr int kMaxKernelWidth = kMaxKernelRadius + 1; SkV2 fOffsetsAndKernel[kMaxKernelWidth]; int fRadius; diff --git a/src/opts/SkVM_opts.h b/src/opts/SkVM_opts.h index 6cf12b1ff5..af87d40458 100644 --- a/src/opts/SkVM_opts.h +++ b/src/opts/SkVM_opts.h @@ -74,7 +74,7 @@ namespace SkVMInterpreterTypes { Slot* r = few_regs; - if (nregs > (int)SK_ARRAY_COUNT(few_regs)) { + if (nregs > (int)std::size(few_regs)) { // Annoyingly we can't trust that malloc() or new will work with Slot because // the skvx::Vec types may have alignment greater than what they provide. // We'll overallocate one extra register so we can align manually. @@ -272,7 +272,7 @@ namespace SkVMInterpreterTypes { 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63 }; - static_assert(K <= SK_ARRAY_COUNT(iota), ""); + static_assert(K <= std::size(iota), ""); r[d].i32 = n - I32::Load(iota); } break; diff --git a/src/pathops/SkIntersections.cpp b/src/pathops/SkIntersections.cpp index 2b1db9a45f..8361f3b8c8 100644 --- a/src/pathops/SkIntersections.cpp +++ b/src/pathops/SkIntersections.cpp @@ -100,7 +100,7 @@ int SkIntersections::insert(double one, double two, const SkDPoint& pt) { fT[0][index] = one; fT[1][index] = two; ++fUsed; - SkASSERT(fUsed <= SK_ARRAY_COUNT(fPt)); + SkASSERT(fUsed <= std::size(fPt)); return index; } diff --git a/src/pathops/SkIntersections.h b/src/pathops/SkIntersections.h index 71d1c80fcc..6e9ae2bebb 100644 --- a/src/pathops/SkIntersections.h +++ b/src/pathops/SkIntersections.h @@ -200,7 +200,7 @@ public: } void setMax(int max) { - SkASSERT(max <= (int) SK_ARRAY_COUNT(fPt)); + SkASSERT(max <= (int) std::size(fPt)); fMax = max; } diff --git a/src/pathops/SkOpEdgeBuilder.cpp b/src/pathops/SkOpEdgeBuilder.cpp index 927d9ae132..ba005f02ce 100644 --- a/src/pathops/SkOpEdgeBuilder.cpp +++ b/src/pathops/SkOpEdgeBuilder.cpp @@ -208,10 +208,10 @@ bool SkOpEdgeBuilder::walk() { if (SkChopQuadAtMaxCurvature(pointsPtr, pair) == 1) { goto addOneQuad; } - if (!SkScalarsAreFinite(&pair[0].fX, SK_ARRAY_COUNT(pair) * 2)) { + if (!SkScalarsAreFinite(&pair[0].fX, std::size(pair) * 2)) { return false; } - for (unsigned index = 0; index < SK_ARRAY_COUNT(pair); ++index) { + for (unsigned index = 0; index < std::size(pair); ++index) { pair[index] = force_small_to_zero(pair[index]); } SkPoint cStorage[2][2]; @@ -269,7 +269,7 @@ bool SkOpEdgeBuilder::walk() { fContourBuilder.addCubic(pointsPtr); break; } - SkASSERT(breaks <= (int) SK_ARRAY_COUNT(splitT)); + SkASSERT(breaks <= (int) std::size(splitT)); struct Splitsville { double fT[2]; SkPoint fPts[4]; @@ -277,7 +277,7 @@ bool SkOpEdgeBuilder::walk() { SkPath::Verb fVerb; bool fCanAdd; } splits[4]; - SkASSERT(SK_ARRAY_COUNT(splits) == SK_ARRAY_COUNT(splitT) + 1); + SkASSERT(std::size(splits) == std::size(splitT) + 1); SkTQSort(splitT, splitT + breaks); for (int index = 0; index <= breaks; ++index) { Splitsville* split = &splits[index]; @@ -306,7 +306,7 @@ bool SkOpEdgeBuilder::walk() { split->fPts[0] = splits[prior].fPts[0]; } int next = index; - int breakLimit = std::min(breaks, (int) SK_ARRAY_COUNT(splits) - 1); + int breakLimit = std::min(breaks, (int) std::size(splits) - 1); while (next < breakLimit && !splits[next + 1].fCanAdd) { ++next; } diff --git a/src/pathops/SkPathOpsDebug.cpp b/src/pathops/SkPathOpsDebug.cpp index 7c89792539..45c04821b8 100644 --- a/src/pathops/SkPathOpsDebug.cpp +++ b/src/pathops/SkPathOpsDebug.cpp @@ -564,7 +564,7 @@ void SkOpGlobalState::debugAddToGlobalCoinDicts() { #if DEBUG_T_SECT_LOOP_COUNT void SkOpGlobalState::debugAddLoopCount(SkIntersections* i, const SkIntersectionHelper& wt, const SkIntersectionHelper& wn) { - for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { + for (int index = 0; index < (int) std::size(fDebugLoopCount); ++index) { SkIntersections::DebugLoop looper = (SkIntersections::DebugLoop) index; if (fDebugLoopCount[index] >= i->debugLoopCount(looper)) { continue; @@ -584,7 +584,7 @@ void SkOpGlobalState::debugAddLoopCount(SkIntersections* i, const SkIntersection } void SkOpGlobalState::debugDoYourWorst(SkOpGlobalState* local) { - for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { + for (int index = 0; index < (int) std::size(fDebugLoopCount); ++index) { if (fDebugLoopCount[index] >= local->fDebugLoopCount[index]) { continue; } @@ -627,7 +627,7 @@ static void dump_curve(SkPath::Verb verb, const SkPoint& pts, float weight) { void SkOpGlobalState::debugLoopReport() { const char* loops[] = { "iterations", "coinChecks", "perpCalcs" }; SkDebugf("\n"); - for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { + for (int index = 0; index < (int) std::size(fDebugLoopCount); ++index) { SkDebugf("%s: %d\n", loops[index], fDebugLoopCount[index]); dump_curve(fDebugWorstVerb[index * 2], fDebugWorstPts[index * 2 * 4], fDebugWorstWeight[index * 2]); diff --git a/src/pathops/SkPathOpsTSect.cpp b/src/pathops/SkPathOpsTSect.cpp index b2e66c3105..58011cada7 100644 --- a/src/pathops/SkPathOpsTSect.cpp +++ b/src/pathops/SkPathOpsTSect.cpp @@ -1084,7 +1084,7 @@ int SkTSect::linesIntersect(SkTSpan* span, if (thisRayI.used() > 1) { int ptMatches = 0; for (int tIndex = 0; tIndex < thisRayI.used(); ++tIndex) { - for (int lIndex = 0; lIndex < (int) SK_ARRAY_COUNT(thisLine.fPts); ++lIndex) { + for (int lIndex = 0; lIndex < (int) std::size(thisLine.fPts); ++lIndex) { ptMatches += thisRayI.pt(tIndex).approximatelyEqual(thisLine.fPts[lIndex]); } } @@ -1095,7 +1095,7 @@ int SkTSect::linesIntersect(SkTSpan* span, if (oppRayI.used() > 1) { int ptMatches = 0; for (int oIndex = 0; oIndex < oppRayI.used(); ++oIndex) { - for (int lIndex = 0; lIndex < (int) SK_ARRAY_COUNT(oppLine.fPts); ++lIndex) { + for (int lIndex = 0; lIndex < (int) std::size(oppLine.fPts); ++lIndex) { ptMatches += oppRayI.pt(oIndex).approximatelyEqual(oppLine.fPts[lIndex]); } } diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp index a2de621cf3..64a9e7acb4 100644 --- a/src/pdf/SkPDFBitmap.cpp +++ b/src/pdf/SkPDFBitmap.cpp @@ -114,7 +114,7 @@ static void do_deflated_alpha(const SkPixmap& pm, SkPDFDocument* doc, SkPDFIndir const uint32_t* stop = ptr + pm.height() * pm.width(); uint8_t byteBuffer[4092]; - uint8_t* bufferStop = byteBuffer + SK_ARRAY_COUNT(byteBuffer); + uint8_t* bufferStop = byteBuffer + std::size(byteBuffer); uint8_t* dst = byteBuffer; while (ptr != stop) { *dst++ = 0xFF & ((*ptr++) >> SK_BGRA_A32_SHIFT); @@ -162,8 +162,8 @@ static void do_deflated_image(const SkPixmap& pm, SkASSERT(pm.colorType() == kBGRA_8888_SkColorType); SkASSERT(pm.rowBytes() == (size_t)pm.width() * 4); uint8_t byteBuffer[3072]; - static_assert(SK_ARRAY_COUNT(byteBuffer) % 3 == 0, ""); - uint8_t* bufferStop = byteBuffer + SK_ARRAY_COUNT(byteBuffer); + static_assert(std::size(byteBuffer) % 3 == 0, ""); + uint8_t* bufferStop = byteBuffer + std::size(byteBuffer); uint8_t* dst = byteBuffer; for (int y = 0; y < pm.height(); ++y) { const SkColor* src = pm.addr32(0, y); diff --git a/src/pdf/SkPDFResourceDict.cpp b/src/pdf/SkPDFResourceDict.cpp index 6705b04436..a4eeed3029 100644 --- a/src/pdf/SkPDFResourceDict.cpp +++ b/src/pdf/SkPDFResourceDict.cpp @@ -29,7 +29,7 @@ static char* get_resource_name(char dst[kMaxResourceNameLength], SkPDFResourceTy 'X', // kXObject 'F' // kFont }; - SkASSERT((unsigned)type < SK_ARRAY_COUNT(kResourceTypePrefixes)); + SkASSERT((unsigned)type < std::size(kResourceTypePrefixes)); dst[0] = kResourceTypePrefixes[(unsigned)type]; return SkStrAppendS32(dst + 1, key); } @@ -49,7 +49,7 @@ static const char* resource_name(SkPDFResourceType type) { "XObject", "Font" }; - SkASSERT((unsigned)type < SK_ARRAY_COUNT(kResourceTypeNames)); + SkASSERT((unsigned)type < std::size(kResourceTypeNames)); return kResourceTypeNames[(unsigned)type]; } @@ -74,7 +74,7 @@ static void add_subdict(const std::vector& resourceList, static std::unique_ptr make_proc_set() { auto procSets = SkPDFMakeArray(); static const char kProcs[][7] = { "PDF", "Text", "ImageB", "ImageC", "ImageI"}; - procSets->reserve(SK_ARRAY_COUNT(kProcs)); + procSets->reserve(std::size(kProcs)); for (const char* proc : kProcs) { procSets->appendName(proc); } diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp index c16b2c1cf6..5dc4d0bb72 100644 --- a/src/ports/SkFontConfigInterface_direct.cpp +++ b/src/ports/SkFontConfigInterface_direct.cpp @@ -411,7 +411,7 @@ static SkFontStyle skfontstyle_from_fcpattern(FcPattern* pattern) { { FC_WEIGHT_EXTRABLACK, SkFS::kExtraBlack_Weight }, }; SkScalar weight = map_ranges(get_int(pattern, FC_WEIGHT, FC_WEIGHT_REGULAR), - weightRanges, SK_ARRAY_COUNT(weightRanges)); + weightRanges, std::size(weightRanges)); static constexpr MapRanges widthRanges[] = { { FC_WIDTH_ULTRACONDENSED, SkFS::kUltraCondensed_Width }, @@ -425,7 +425,7 @@ static SkFontStyle skfontstyle_from_fcpattern(FcPattern* pattern) { { FC_WIDTH_ULTRAEXPANDED, SkFS::kUltraExpanded_Width }, }; SkScalar width = map_ranges(get_int(pattern, FC_WIDTH, FC_WIDTH_NORMAL), - widthRanges, SK_ARRAY_COUNT(widthRanges)); + widthRanges, std::size(widthRanges)); SkFS::Slant slant = SkFS::kUpright_Slant; switch (get_int(pattern, FC_SLANT, FC_SLANT_ROMAN)) { @@ -455,7 +455,7 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { { SkFS::kBlack_Weight, FC_WEIGHT_BLACK }, { SkFS::kExtraBlack_Weight, FC_WEIGHT_EXTRABLACK }, }; - int weight = map_ranges(style.weight(), weightRanges, SK_ARRAY_COUNT(weightRanges)); + int weight = map_ranges(style.weight(), weightRanges, std::size(weightRanges)); static constexpr MapRanges widthRanges[] = { { SkFS::kUltraCondensed_Width, FC_WIDTH_ULTRACONDENSED }, @@ -468,7 +468,7 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { { SkFS::kExtraExpanded_Width, FC_WIDTH_EXTRAEXPANDED }, { SkFS::kUltraExpanded_Width, FC_WIDTH_ULTRAEXPANDED }, }; - int width = map_ranges(style.width(), widthRanges, SK_ARRAY_COUNT(widthRanges)); + int width = map_ranges(style.width(), widthRanges, std::size(widthRanges)); int slant = FC_SLANT_ROMAN; switch (style.slant()) { diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 35d196be94..fbfb0bb59e 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -2151,7 +2151,7 @@ bool SkTypeface_FreeType::Scanner::scanFont( { "ultraheavy", SkFontStyle::kExtraBlack_Weight }, { "ultralight", SkFontStyle::kExtraLight_Weight }, }; - int const index = SkStrLCSearch(&commonWeights[0].name, SK_ARRAY_COUNT(commonWeights), + int const index = SkStrLCSearch(&commonWeights[0].name, std::size(commonWeights), psFontInfo.weight, sizeof(commonWeights[0])); if (index >= 0) { weight = commonWeights[index].weight; diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 8e097ca42e..d22cf559d1 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -1718,7 +1718,7 @@ std::unique_ptr LogFontTypeface::onGetAdvancedMetrics // This probably isn't very good with an italic font. min_width = SHRT_MAX; info->fStemV = 0; - for (size_t i = 0; i < SK_ARRAY_COUNT(stem_chars); i++) { + for (size_t i = 0; i < std::size(stem_chars); i++) { ABC abcWidths; if (GetCharABCWidths(hdc, stem_chars[i], stem_chars[i], &abcWidths)) { int16_t width = abcWidths.abcB; @@ -1735,7 +1735,7 @@ std::unique_ptr LogFontTypeface::onGetAdvancedMetrics //Placeholder representation of a Base64 encoded GUID from create_unique_font_name. #define BASE64_GUID_ID "XXXXXXXXXXXXXXXXXXXXXXXX" //Length of GUID representation from create_id, including nullptr terminator. -#define BASE64_GUID_ID_LEN SK_ARRAY_COUNT(BASE64_GUID_ID) +#define BASE64_GUID_ID_LEN std::size(BASE64_GUID_ID) static_assert(BASE64_GUID_ID_LEN < LF_FACESIZE, "GUID_longer_than_facesize"); @@ -1805,7 +1805,7 @@ static sk_sp create_from_stream(std::unique_ptr strea // Create a unique and unpredictable font name. // Avoids collisions and access from CSS. char familyName[BASE64_GUID_ID_LEN]; - const int familyNameSize = SK_ARRAY_COUNT(familyName); + const int familyNameSize = std::size(familyName); if (FAILED(create_unique_font_name(familyName, familyNameSize))) { return nullptr; } @@ -1839,7 +1839,7 @@ std::unique_ptr LogFontTypeface::onOpenStream(int* ttcIndex) cons std::unique_ptr stream; DWORD tables[2] = {kTTCTag, 0}; - for (size_t i = 0; i < SK_ARRAY_COUNT(tables); i++) { + for (size_t i = 0; i < std::size(tables); i++) { DWORD bufferSize = GetFontData(hdc, tables[i], 0, nullptr, 0); if (bufferSize == GDI_ERROR) { call_ensure_accessible(lf); diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 49fc79adde..c2a2908f54 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -562,7 +562,7 @@ static char const * const gSystemFontUseStrings[] = { sk_sp SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { if (custom) { SkASSERT(0 <= custom->fSystemFontUse); - SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings)); + SkASSERT(custom->fSystemFontUse < std::size(gSystemFontUseStrings)); SkDEBUGF("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n", gSystemFontUseStrings[custom->fSystemFontUse], custom->fBasePath, diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp index 72ccb029ea..73a096dfba 100644 --- a/src/ports/SkFontMgr_custom.cpp +++ b/src/ports/SkFontMgr_custom.cpp @@ -169,7 +169,7 @@ SkFontMgr_Custom::SkFontMgr_Custom(const SystemFontLoader& loader) : fDefaultFam static const char* defaultNames[] = { "Arial", "Verdana", "Times New Roman", "Droid Sans", nullptr }; - for (size_t i = 0; i < SK_ARRAY_COUNT(defaultNames); ++i) { + for (size_t i = 0; i < std::size(defaultNames); ++i) { sk_sp set(this->onMatchFamily(defaultNames[i])); if (nullptr == set) { continue; diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index c87f20ac7d..d79ab014b9 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -220,7 +220,7 @@ static SkWeakReturn is_weak(FcPattern* pattern, const char object[], int id) { // However, there appears to be no way to match/sort without it. SkAutoFcConfig config; FcFontSet* fontSets[1] = { fontSet }; - SkAutoFcPattern match(FcFontSetMatch(config, fontSets, SK_ARRAY_COUNT(fontSets), + SkAutoFcPattern match(FcFontSetMatch(config, fontSets, std::size(fontSets), minimal, &result)); FcLangSet* matchLangSet; @@ -321,7 +321,7 @@ static SkFontStyle skfontstyle_from_fcpattern(FcPattern* pattern) { { FC_WEIGHT_EXTRABLACK, SkFS::kExtraBlack_Weight }, }; SkScalar weight = map_ranges(get_int(pattern, FC_WEIGHT, FC_WEIGHT_REGULAR), - weightRanges, SK_ARRAY_COUNT(weightRanges)); + weightRanges, std::size(weightRanges)); static constexpr MapRanges widthRanges[] = { { FC_WIDTH_ULTRACONDENSED, SkFS::kUltraCondensed_Width }, @@ -335,7 +335,7 @@ static SkFontStyle skfontstyle_from_fcpattern(FcPattern* pattern) { { FC_WIDTH_ULTRAEXPANDED, SkFS::kUltraExpanded_Width }, }; SkScalar width = map_ranges(get_int(pattern, FC_WIDTH, FC_WIDTH_NORMAL), - widthRanges, SK_ARRAY_COUNT(widthRanges)); + widthRanges, std::size(widthRanges)); SkFS::Slant slant = SkFS::kUpright_Slant; switch (get_int(pattern, FC_SLANT, FC_SLANT_ROMAN)) { @@ -368,7 +368,7 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { { SkFS::kBlack_Weight, FC_WEIGHT_BLACK }, { SkFS::kExtraBlack_Weight, FC_WEIGHT_EXTRABLACK }, }; - int weight = map_ranges(style.weight(), weightRanges, SK_ARRAY_COUNT(weightRanges)); + int weight = map_ranges(style.weight(), weightRanges, std::size(weightRanges)); static constexpr MapRanges widthRanges[] = { { SkFS::kUltraCondensed_Width, FC_WIDTH_ULTRACONDENSED }, @@ -381,7 +381,7 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { { SkFS::kExtraExpanded_Width, FC_WIDTH_EXTRAEXPANDED }, { SkFS::kUltraExpanded_Width, FC_WIDTH_ULTRAEXPANDED }, }; - int width = map_ranges(style.width(), widthRanges, SK_ARRAY_COUNT(widthRanges)); + int width = map_ranges(style.width(), widthRanges, std::size(widthRanges)); int slant = FC_SLANT_ROMAN; switch (style.slant()) { @@ -620,7 +620,7 @@ class SkFontMgr_fontconfig : public SkFontMgr { FcResult result; FcFontSet* fontSets[1] = { fFontSet }; return FcFontSetMatch(fFontMgr->fFC, - fontSets, SK_ARRAY_COUNT(fontSets), + fontSets, std::size(fontSets), pattern, &result); }()); @@ -649,7 +649,7 @@ class SkFontMgr_fontconfig : public SkFontMgr { SkTDArray sizes; static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication }; - for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setIndex) { + for (int setIndex = 0; setIndex < (int)std::size(fcNameSet); ++setIndex) { // Return value of FcConfigGetFonts must not be destroyed. FcFontSet* allFonts(FcConfigGetFonts(fcconfig, fcNameSet[setIndex])); if (nullptr == allFonts) { @@ -851,7 +851,7 @@ protected: // The patterns are exactly the same except for the FC_FILE. // It should be possible to collapse these patterns by normalizing. static const FcSetName fcNameSet[] = { FcSetSystem, FcSetApplication }; - for (int setIndex = 0; setIndex < (int)SK_ARRAY_COUNT(fcNameSet); ++setIndex) { + for (int setIndex = 0; setIndex < (int)std::size(fcNameSet); ++setIndex) { // Return value of FcConfigGetFonts must not be destroyed. FcFontSet* allFonts(FcConfigGetFonts(fFC, fcNameSet[setIndex])); if (nullptr == allFonts) { diff --git a/src/ports/SkFontMgr_mac_ct.cpp b/src/ports/SkFontMgr_mac_ct.cpp index f5af81e36c..43edf326bb 100644 --- a/src/ports/SkFontMgr_mac_ct.cpp +++ b/src/ports/SkFontMgr_mac_ct.cpp @@ -216,7 +216,7 @@ static const char* map_css_names(const char* name) { { "monospace", "Courier" } }; - for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { + for (size_t i = 0; i < std::size(gPairs); i++) { if (strcmp(name, gPairs[i].fFrom) == 0) { return gPairs[i].fTo; } diff --git a/src/ports/SkTypeface_mac_ct.cpp b/src/ports/SkTypeface_mac_ct.cpp index 970e131b6f..8923f41804 100644 --- a/src/ports/SkTypeface_mac_ct.cpp +++ b/src/ports/SkTypeface_mac_ct.cpp @@ -343,7 +343,7 @@ CGFloat SkCTFontCTWeightForCSSWeight(int fontstyleWeight) { } }); static constexpr Interpolator nativeInterpolator( - nativeWeightMappings, SK_ARRAY_COUNT(nativeWeightMappings)); + nativeWeightMappings, std::size(nativeWeightMappings)); return nativeInterpolator.map(fontstyleWeight); } @@ -374,9 +374,9 @@ static int ct_weight_to_fontstyle(CGFloat cgWeight, bool fromDataProvider) { } }); static constexpr Interpolator nativeInterpolator( - nativeWeightMappings, SK_ARRAY_COUNT(nativeWeightMappings)); + nativeWeightMappings, std::size(nativeWeightMappings)); static constexpr Interpolator dataProviderInterpolator( - dataProviderWeightMappings, SK_ARRAY_COUNT(dataProviderWeightMappings)); + dataProviderWeightMappings, std::size(dataProviderWeightMappings)); return fromDataProvider ? dataProviderInterpolator.map(cgWeight) : nativeInterpolator.map(cgWeight); @@ -392,7 +392,7 @@ CGFloat SkCTFontCTWidthForCSSWidth(int fontstyleWidth) { { 0, -0.5 }, { 10, 0.5 }, }; - static constexpr Interpolator interpolator(widthMappings, SK_ARRAY_COUNT(widthMappings)); + static constexpr Interpolator interpolator(widthMappings, std::size(widthMappings)); return interpolator.map(fontstyleWidth); } @@ -406,7 +406,7 @@ static int ct_width_to_fontstyle(CGFloat cgWidth) { { -0.5, 0 }, { 0.5, 10 }, }; - static constexpr Interpolator interpolator(widthMappings, SK_ARRAY_COUNT(widthMappings)); + static constexpr Interpolator interpolator(widthMappings, std::size(widthMappings)); return interpolator.map(cgWidth); } diff --git a/src/sfnt/SkOTTable_name.cpp b/src/sfnt/SkOTTable_name.cpp index 90d59558ec..8ceef664e8 100644 --- a/src/sfnt/SkOTTable_name.cpp +++ b/src/sfnt/SkOTTable_name.cpp @@ -574,7 +574,7 @@ bool SkOTTableName::Iterator::next(SkOTTableName::Iterator::Record& record) { // Handle format 0 languages, translating them into BCP 47. const BCP47FromLanguageId target = { languageID, "" }; int languageIndex = SkTSearch( - BCP47FromLanguageID, SK_ARRAY_COUNT(BCP47FromLanguageID), target, sizeof(target)); + BCP47FromLanguageID, std::size(BCP47FromLanguageID), target, sizeof(target)); if (languageIndex >= 0) { record.language = BCP47FromLanguageID[languageIndex].bcp47; return true; diff --git a/src/sfnt/SkOTUtils.cpp b/src/sfnt/SkOTUtils.cpp index b80f969aa2..a679ae41b0 100644 --- a/src/sfnt/SkOTUtils.cpp +++ b/src/sfnt/SkOTUtils.cpp @@ -191,7 +191,7 @@ sk_sp SkOTUtils::LocalizedStrings_NameTable::MakeForFamilyNames(const SkTypeface& typeface) { return Make(typeface, SkOTUtils::LocalizedStrings_NameTable::familyNameTypes, - SK_ARRAY_COUNT(SkOTUtils::LocalizedStrings_NameTable::familyNameTypes)); + std::size(SkOTUtils::LocalizedStrings_NameTable::familyNameTypes)); } bool SkOTUtils::LocalizedStrings_NameTable::next(SkTypeface::LocalizedString* localizedString) { diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp index 679354df02..4447ba60a0 100644 --- a/src/shaders/SkPerlinNoiseShader.cpp +++ b/src/shaders/SkPerlinNoiseShader.cpp @@ -803,11 +803,11 @@ void GrPerlinNoise2Effect::Impl::emitCode(EmitArgs& args) { SkString noiseFuncName = fragBuilder->getMangledFunctionName("noiseFuncName"); if (pne.stitchTiles()) { fragBuilder->emitFunction(SkSLType::kHalf, noiseFuncName.c_str(), - {gPerlinNoiseStitchArgs, SK_ARRAY_COUNT(gPerlinNoiseStitchArgs)}, + {gPerlinNoiseStitchArgs, std::size(gPerlinNoiseStitchArgs)}, noiseCode.c_str()); } else { fragBuilder->emitFunction(SkSLType::kHalf, noiseFuncName.c_str(), - {gPerlinNoiseArgs, SK_ARRAY_COUNT(gPerlinNoiseArgs)}, + {gPerlinNoiseArgs, std::size(gPerlinNoiseArgs)}, noiseCode.c_str()); } diff --git a/src/sksl/SkSLMangler.cpp b/src/sksl/SkSLMangler.cpp index eaba2d6eff..9fcb723b71 100644 --- a/src/sksl/SkSLMangler.cpp +++ b/src/sksl/SkSLMangler.cpp @@ -52,7 +52,7 @@ std::string Mangler::uniqueName(std::string_view baseName, SymbolTable* symbolTa // This code is a performance hotspot. Assemble the string manually to save a few cycles. char uniqueName[256]; uniqueName[0] = '_'; - char* uniqueNameEnd = uniqueName + SK_ARRAY_COUNT(uniqueName); + char* uniqueNameEnd = uniqueName + std::size(uniqueName); for (;;) { // _123 char* endPtr = SkStrAppendS32(uniqueName + 1, fCounter++); diff --git a/src/sksl/codegen/SkSLVMCodeGenerator.cpp b/src/sksl/codegen/SkSLVMCodeGenerator.cpp index 68f8799ffb..67843b4e34 100644 --- a/src/sksl/codegen/SkSLVMCodeGenerator.cpp +++ b/src/sksl/codegen/SkSLVMCodeGenerator.cpp @@ -1341,7 +1341,7 @@ Value SkVMGenerator::writeIntrinsicCall(const FunctionCall& c) { const size_t nargs = c.arguments().size(); const size_t kMaxArgs = 3; // eg: clamp, mix, smoothstep Value args[kMaxArgs]; - SkASSERT(nargs >= 1 && nargs <= SK_ARRAY_COUNT(args)); + SkASSERT(nargs >= 1 && nargs <= std::size(args)); // All other intrinsics have at most three args, and those can all be evaluated up front: for (size_t i = 0; i < nargs; ++i) { @@ -2118,13 +2118,13 @@ skvm::Color ProgramToSkVM(const Program& program, switch (param->modifiers().fLayout.fBuiltin) { case SK_MAIN_COORDS_BUILTIN: SkASSERT(param->type().slotCount() == 2); - SkASSERT((argSlots + 2) <= SK_ARRAY_COUNT(args)); + SkASSERT((argSlots + 2) <= std::size(args)); args[argSlots++] = local.x.id; args[argSlots++] = local.y.id; break; case SK_INPUT_COLOR_BUILTIN: SkASSERT(param->type().slotCount() == 4); - SkASSERT((argSlots + 4) <= SK_ARRAY_COUNT(args)); + SkASSERT((argSlots + 4) <= std::size(args)); args[argSlots++] = inputColor.r.id; args[argSlots++] = inputColor.g.id; args[argSlots++] = inputColor.b.id; @@ -2132,7 +2132,7 @@ skvm::Color ProgramToSkVM(const Program& program, break; case SK_DEST_COLOR_BUILTIN: SkASSERT(param->type().slotCount() == 4); - SkASSERT((argSlots + 4) <= SK_ARRAY_COUNT(args)); + SkASSERT((argSlots + 4) <= std::size(args)); args[argSlots++] = destColor.r.id; args[argSlots++] = destColor.g.id; args[argSlots++] = destColor.b.id; @@ -2143,7 +2143,7 @@ skvm::Color ProgramToSkVM(const Program& program, return {}; } } - SkASSERT(argSlots <= SK_ARRAY_COUNT(args)); + SkASSERT(argSlots <= std::size(args)); // Make sure that the SkVMDebugTrace starts from a clean slate. if (debugTrace) { diff --git a/src/sksl/ir/SkSLFunctionCall.cpp b/src/sksl/ir/SkSLFunctionCall.cpp index 5a7ed5456b..83db5f77e6 100644 --- a/src/sksl/ir/SkSLFunctionCall.cpp +++ b/src/sksl/ir/SkSLFunctionCall.cpp @@ -755,7 +755,7 @@ static std::unique_ptr optimize_intrinsic_call(const Context& contex } double dmat[16]; - std::copy(mat, mat + SK_ARRAY_COUNT(mat), dmat); + std::copy(mat, mat + std::size(mat), dmat); return assemble_compound(context, arguments[0]->fPosition, returnType, dmat); } // 8.7 : Vector Relational Functions diff --git a/src/sksl/ir/SkSLFunctionDeclaration.cpp b/src/sksl/ir/SkSLFunctionDeclaration.cpp index f97d82aa1b..a0b5e6d1e6 100644 --- a/src/sksl/ir/SkSLFunctionDeclaration.cpp +++ b/src/sksl/ir/SkSLFunctionDeclaration.cpp @@ -129,7 +129,7 @@ static bool check_parameters(const Context& context, m.fLayout.fBuiltin = SK_MAIN_COORDS_BUILTIN; modifiersChanged = true; } else if (typeIsValidForColor(type) && - builtinColorIndex < SK_ARRAY_COUNT(kBuiltinColorIDs)) { + builtinColorIndex < std::size(kBuiltinColorIDs)) { m.fLayout.fBuiltin = kBuiltinColorIDs[builtinColorIndex++]; modifiersChanged = true; } diff --git a/src/sksl/tracing/SkVMDebugTrace.cpp b/src/sksl/tracing/SkVMDebugTrace.cpp index 1f5f40729f..43d75dd690 100644 --- a/src/sksl/tracing/SkVMDebugTrace.cpp +++ b/src/sksl/tracing/SkVMDebugTrace.cpp @@ -78,7 +78,7 @@ std::string SkVMDebugTrace::slotValueToString(int slotIndex, double value) const } default: { char buffer[32]; - snprintf(buffer, SK_ARRAY_COUNT(buffer), "%.8g", value); + snprintf(buffer, std::size(buffer), "%.8g", value); return buffer; } } @@ -253,7 +253,7 @@ void SkVMDebugTrace::writeTrace(SkWStream* w) const { json.appendS32((int)trace.op); // Skip trailing zeros in the data (since most ops only use one value). - int lastDataIdx = SK_ARRAY_COUNT(trace.data) - 1; + int lastDataIdx = std::size(trace.data) - 1; while (lastDataIdx >= 0 && !trace.data[lastDataIdx]) { --lastDataIdx; } @@ -367,7 +367,7 @@ bool SkVMDebugTrace::readTrace(SkStream* r) { fTraceInfo.push_back(SkVMTraceInfo{}); SkVMTraceInfo& info = fTraceInfo.back(); - if (!element || element->size() < 1 || element->size() > (1 + SK_ARRAY_COUNT(info.data))) { + if (!element || element->size() < 1 || element->size() > (1 + std::size(info.data))) { return false; } const skjson::NumberValue* opVal = (*element)[0]; diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp index 6bfa4ec78b..c29f966eed 100644 --- a/src/svg/SkSVGDevice.cpp +++ b/src/svg/SkSVGDevice.cpp @@ -130,10 +130,10 @@ static const char* cap_map[] = { "round", // kRound_Cap "square" // kSquare_Cap }; -static_assert(SK_ARRAY_COUNT(cap_map) == SkPaint::kCapCount, "missing_cap_map_entry"); +static_assert(std::size(cap_map) == SkPaint::kCapCount, "missing_cap_map_entry"); static const char* svg_cap(SkPaint::Cap cap) { - SkASSERT(cap < SK_ARRAY_COUNT(cap_map)); + SkASSERT(cap < std::size(cap_map)); return cap_map[cap]; } @@ -143,10 +143,10 @@ static const char* join_map[] = { "round", // kRound_Join "bevel" // kBevel_Join }; -static_assert(SK_ARRAY_COUNT(join_map) == SkPaint::kJoinCount, "missing_join_map_entry"); +static_assert(std::size(join_map) == SkPaint::kJoinCount, "missing_join_map_entry"); static const char* svg_join(SkPaint::Join join) { - SkASSERT(join < SK_ARRAY_COUNT(join_map)); + SkASSERT(join < std::size(join_map)); return join_map[join]; } diff --git a/src/utils/SkDashPath.cpp b/src/utils/SkDashPath.cpp index 42e841c137..2d86fb7d48 100644 --- a/src/utils/SkDashPath.cpp +++ b/src/utils/SkDashPath.cpp @@ -22,6 +22,7 @@ #include #include +#include #include static inline int is_even(int x) { @@ -288,7 +289,7 @@ public: pts[2].set(x1 - fNormal.fX, y1 - fNormal.fY); // lineTo pts[3].set(x0 - fNormal.fX, y0 - fNormal.fY); // lineTo - path->addPoly(pts, SK_ARRAY_COUNT(pts), false); + path->addPoly(pts, std::size(pts), false); } private: diff --git a/src/utils/SkJSON.cpp b/src/utils/SkJSON.cpp index 4ff5cae881..f00f95e719 100644 --- a/src/utils/SkJSON.cpp +++ b/src/utils/SkJSON.cpp @@ -289,7 +289,7 @@ static inline float pow10(int32_t exp) { 1.e+025f, 1.e+026f, 1.e+027f, 1.e+028f, 1.e+029f, 1.e+030f, 1.e+031f }; - static constexpr int32_t k_exp_offset = SK_ARRAY_COUNT(g_pow10_table) / 2; + static constexpr int32_t k_exp_offset = std::size(g_pow10_table) / 2; // We only support negative exponents for now. SkASSERT(exp <= 0); diff --git a/src/utils/SkParse.cpp b/src/utils/SkParse.cpp index 40e9e343fd..799f11b69c 100644 --- a/src/utils/SkParse.cpp +++ b/src/utils/SkParse.cpp @@ -7,6 +7,7 @@ #include "include/utils/SkParse.h" +#include // for std::size #include #include @@ -248,12 +249,12 @@ bool SkParse::FindBool(const char str[], bool* value) static const char* gYes[] = { "yes", "1", "true" }; static const char* gNo[] = { "no", "0", "false" }; - if (lookup_str(str, gYes, SK_ARRAY_COUNT(gYes))) + if (lookup_str(str, gYes, std::size(gYes))) { if (value) *value = true; return true; } - else if (lookup_str(str, gNo, SK_ARRAY_COUNT(gNo))) + else if (lookup_str(str, gNo, std::size(gNo))) { if (value) *value = false; return true; diff --git a/src/utils/mac/SkCTFont.cpp b/src/utils/mac/SkCTFont.cpp index 6cd8589639..49adab4ad1 100644 --- a/src/utils/mac/SkCTFont.cpp +++ b/src/utils/mac/SkCTFont.cpp @@ -229,7 +229,7 @@ SkCTFontSmoothBehavior SkCTFontGetSmoothBehavior() { colorspace.get(), kBitmapInfoRGB)); SkUniqueCFRef data(CFDataCreateWithBytesNoCopy( - kCFAllocatorDefault, kSpiderSymbol_ttf, SK_ARRAY_COUNT(kSpiderSymbol_ttf), + kCFAllocatorDefault, kSpiderSymbol_ttf, std::size(kSpiderSymbol_ttf), kCFAllocatorNull)); SkUniqueCFRef desc( CTFontManagerCreateFontDescriptorFromData(data.get())); @@ -298,7 +298,7 @@ SkCTFontWeightMapping& SkCTFontGetNSFontWeightMapping() { SK_KIT_FONT_WEIGHT_PREFIX "FontWeightHeavy", SK_KIT_FONT_WEIGHT_PREFIX "FontWeightBlack", }; - static_assert(SK_ARRAY_COUNT(nsFontWeightNames) == 9, ""); + static_assert(std::size(nsFontWeightNames) == 9, ""); static CGFloat nsFontWeights[11]; static const CGFloat (*selectedNSFontWeights)[11] = &defaultNSFontWeights; @@ -330,7 +330,7 @@ SkCTFontWeightMapping& SkCTFontGetDataFontWeightMapping() { static CGFloat dataFontWeights[11]; static SkOnce once; once([&] { - constexpr size_t dataSize = SK_ARRAY_COUNT(kSpiderSymbol_ttf); + constexpr size_t dataSize = std::size(kSpiderSymbol_ttf); sk_sp data = SkData::MakeWithCopy(kSpiderSymbol_ttf, dataSize); const SkSFNTHeader* sfntHeader = reinterpret_cast(data->data()); const SkSFNTHeader::TableDirectoryEntry* tableEntry = diff --git a/src/utils/win/SkWGL_win.cpp b/src/utils/win/SkWGL_win.cpp index 5f1278010d..8987fbbde9 100644 --- a/src/utils/win/SkWGL_win.cpp +++ b/src/utils/win/SkWGL_win.cpp @@ -393,7 +393,7 @@ static HGLRC create_gl_context(HDC dc, const SkWGLExtensions& extensions, SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT, 0, }; - for (size_t v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) { + for (size_t v = 0; v < std::size(kCoreGLVersions) / 2; ++v) { coreProfileAttribs[1] = kCoreGLVersions[2 * v]; coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1]; glrc = extensions.createContextAttribs(dc, shareContext, coreProfileAttribs); @@ -432,7 +432,7 @@ HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor, int pixelFormatsToTry[] = { -1, -1 }; get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, deepColor, pixelFormatsToTry); for (size_t f = 0; - !set && -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry); + !set && -1 != pixelFormatsToTry[f] && f < std::size(pixelFormatsToTry); ++f) { PIXELFORMATDESCRIPTOR pfd; DescribePixelFormat(dc, pixelFormatsToTry[f], sizeof(pfd), &pfd); diff --git a/src/xml/SkXMLParser.cpp b/src/xml/SkXMLParser.cpp index 7432ae884f..69e9fc44c0 100644 --- a/src/xml/SkXMLParser.cpp +++ b/src/xml/SkXMLParser.cpp @@ -41,7 +41,7 @@ void SkXMLParserError::getErrorString(SkString* str) const SkASSERT(str); SkString temp; if (fCode != kNoError) { - if ((unsigned)fCode < SK_ARRAY_COUNT(gErrorStrings)) + if ((unsigned)fCode < std::size(gErrorStrings)) temp.set(gErrorStrings[fCode - 1]); temp.append(fNoun); } else diff --git a/src/xml/SkXMLWriter.cpp b/src/xml/SkXMLWriter.cpp index 4640d73d93..c1005bf699 100644 --- a/src/xml/SkXMLWriter.cpp +++ b/src/xml/SkXMLWriter.cpp @@ -95,7 +95,7 @@ static const char* escape_char(char c, char storage[2]) { }; const char** array = gEscapeChars; - for (unsigned i = 0; i < SK_ARRAY_COUNT(gEscapeChars); i++) { + for (unsigned i = 0; i < std::size(gEscapeChars); i++) { if (array[i][0] == c) { return &array[i][1]; } diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index f022355e38..01f1a21542 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -63,7 +63,7 @@ //Placeholder representation of a GUID from createId. #define L_GUID_ID L"XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX" //Length of GUID representation from createId, including nullptr terminator. -#define GUID_ID_LEN SK_ARRAY_COUNT(L_GUID_ID) +#define GUID_ID_LEN std::size(L_GUID_ID) /** Formats a GUID and places it into buffer. @@ -170,8 +170,8 @@ HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, SkTScopedComPtr partUri; constexpr size_t size = std::max( - SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + sk_digits_in(), - SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png")); + std::size(L"/Documents/1/Metadata/.png") + sk_digits_in(), + std::size(L"/Metadata/" L_GUID_ID L".png")); wchar_t buffer[size]; if (pageNum > 0) { swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); @@ -196,7 +196,7 @@ HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize, IXpsOMPage** page) { constexpr size_t size = - SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage") + std::size(L"/Documents/1/Pages/.fpage") + sk_digits_in(); wchar_t buffer[size]; swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage", @@ -638,7 +638,7 @@ HRESULT SkXPSDevice::createXpsImageBrush( "Could not create stream from png data."); const size_t size = - SK_ARRAY_COUNT(L"/Documents/1/Resources/Images/" L_GUID_ID L".png"); + std::size(L"/Documents/1/Resources/Images/" L_GUID_ID L".png"); wchar_t buffer[size]; wchar_t id[GUID_ID_LEN]; HR(this->createId(id, GUID_ID_LEN)); @@ -1238,7 +1238,7 @@ void SkXPSDevice::internalDrawRect(const SkRect& r, { r.fRight, r.fTop }, }; if (!xpsTransformsPath && transformRect) { - this->localToDevice().mapPoints(points, SK_ARRAY_COUNT(points)); + this->localToDevice().mapPoints(points, std::size(points)); } HRV(this->createXpsQuad(points, stroke, fill, &rectFigure)); } @@ -1758,7 +1758,7 @@ HRESULT SkXPSDevice::CreateTypefaceUse(const SkFont& font, "Could not create font stream."); const size_t size = - SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf"); + std::size(L"/Resources/Fonts/" L_GUID_ID L".odttf"); wchar_t buffer[size]; wchar_t id[GUID_ID_LEN]; HR(this->createId(id, GUID_ID_LEN)); diff --git a/toolchain/linux_trampolines/IWYU_mapping.imp b/toolchain/linux_trampolines/IWYU_mapping.imp index dbd33ed02c..95ce7586eb 100644 --- a/toolchain/linux_trampolines/IWYU_mapping.imp +++ b/toolchain/linux_trampolines/IWYU_mapping.imp @@ -22,6 +22,20 @@ { include: ["<__iterator/access.h>", "private", "", "public"] }, { include: ["<__iterator/distance.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__iterator/size.h>", "private", "", "public"] }, + { include: ["<__locale>", "private", "", "public"] }, { include: ["<__memory/shared_ptr.h>", "private", "", "public"] },