Update Span to not need toSpan helper Use std::data() and std::size() to extract those attributes from the incoming type (for our purposes, a std::vector). Diffs= 82de255b9 Update Span to not need toSpan helper
diff --git a/.rive_head b/.rive_head index 75439fb..ae0cfb9 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -c07c43a80d58db1c30e914dad7e2887a90aa5119 +82de255b9de142d023036bafb340bf5f73e5ffbb
diff --git a/include/rive/math/raw_path.hpp b/include/rive/math/raw_path.hpp index 00d0121..cb03941 100644 --- a/include/rive/math/raw_path.hpp +++ b/include/rive/math/raw_path.hpp
@@ -51,11 +51,11 @@ void transformInPlace(const Mat2D&); RawPath operator*(const Mat2D& mat) const { return this->transform(mat); } - Span<const Vec2D> points() const { return toSpan(m_Points); } - Span<Vec2D> points() { return toSpan(m_Points); } + Span<const Vec2D> points() const { return m_Points; } + Span<Vec2D> points() { return m_Points; } - Span<const PathVerb> verbs() const { return toSpan(m_Verbs); } - Span<PathVerb> verbs() { return toSpan(m_Verbs); } + Span<const PathVerb> verbs() const { return m_Verbs; } + Span<PathVerb> verbs() { return m_Verbs; } Span<const uint8_t> verbsU8() const { const uint8_t* ptr = (const uint8_t*)m_Verbs.data();
diff --git a/include/rive/span.hpp b/include/rive/span.hpp index 4aaa955..d5910a8 100644 --- a/include/rive/span.hpp +++ b/include/rive/span.hpp
@@ -7,6 +7,9 @@ #include "rive/rive_types.hpp" +#include <initializer_list> +#include <type_traits> + /* * Span : cheap impl of std::span (which is C++20) * @@ -27,6 +30,8 @@ template <typename U, typename = typename std::enable_if<std::is_same<const U, T>::value>::type> constexpr Span(const Span<U>& that) : Span(that.data(), that.size()) {} constexpr Span(const Span&) = default; + template <typename Container> constexpr Span(Container& c) : Span{std::data(c), std::size(c)} {} + constexpr Span(std::initializer_list<T> il) : Span(std::data(il), std::size(il)) {} constexpr T& operator[](size_t index) const { assert(index < m_Size); @@ -69,12 +74,6 @@ typedef size_t size_type; }; -template <typename Container> -inline auto toSpan(Container& c) - -> Span<typename std::remove_reference<decltype(*(c.data()))>::type> { - return {c.data(), c.size()}; -} - } // namespace rive #endif
diff --git a/rivinfo/main.cpp b/rivinfo/main.cpp index d4a9b37..485d9f1 100644 --- a/rivinfo/main.cpp +++ b/rivinfo/main.cpp
@@ -129,7 +129,7 @@ } static rive::NoOpFactory gFactory; - return rive::File::import(rive::toSpan(bytes), &gFactory); + return rive::File::import(bytes, &gFactory); } static bool is_arg(const char arg[], const char target[], const char alt[] = nullptr) {
diff --git a/skia/thumbnail_generator/src/main.cpp b/skia/thumbnail_generator/src/main.cpp index 50a955d..cfc4eb5 100644 --- a/skia/thumbnail_generator/src/main.cpp +++ b/skia/thumbnail_generator/src/main.cpp
@@ -53,7 +53,7 @@ } fclose(fp); - auto file = rive::File::import(rive::toSpan(bytes), &factory); + auto file = rive::File::import(bytes, &factory); if (!file) { fprintf(stderr, "Failed to read rive file.\n"); return 1;
diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index 1ec539c..9f6d578 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp
@@ -398,7 +398,7 @@ bool StateMachineInstance::advance(float seconds) { m_NeedsAdvance = false; for (size_t i = 0; i < m_LayerCount; i++) { - if (m_Layers[i].advance(seconds, toSpan(m_InputInstances))) { + if (m_Layers[i].advance(seconds, m_InputInstances)) { m_NeedsAdvance = true; } }
diff --git a/src/assets/file_asset_contents.cpp b/src/assets/file_asset_contents.cpp index c62b80c..84270a9 100644 --- a/src/assets/file_asset_contents.cpp +++ b/src/assets/file_asset_contents.cpp
@@ -24,4 +24,4 @@ assert(false); } -Span<const uint8_t> FileAssetContents::bytes() const { return toSpan(m_Bytes); } +Span<const uint8_t> FileAssetContents::bytes() const { return m_Bytes; }
diff --git a/src/math/contour_measure.cpp b/src/math/contour_measure.cpp index de325c5..b3421d4 100644 --- a/src/math/contour_measure.cpp +++ b/src/math/contour_measure.cpp
@@ -217,8 +217,8 @@ const auto start = m_segments[startIndex]; const auto end = m_segments[endIndex]; - const auto startT = compute_t(toSpan(m_segments), startIndex, startDist); - const auto endT = compute_t(toSpan(m_segments), endIndex, endDist); + const auto startT = compute_t(m_segments, startIndex, startDist); + const auto endT = compute_t(m_segments, endIndex, endDist); if (start.m_ptIndex == end.m_ptIndex) { start.extract(dst, startT, endT, m_points.data(), startWithMove);
diff --git a/src/nested_artboard.cpp b/src/nested_artboard.cpp index 18ae876..f9b3834 100644 --- a/src/nested_artboard.cpp +++ b/src/nested_artboard.cpp
@@ -129,7 +129,7 @@ return false; } -Span<NestedAnimation*> NestedArtboard::nestedAnimations() { return toSpan(m_NestedAnimations); } +Span<NestedAnimation*> NestedArtboard::nestedAnimations() { return m_NestedAnimations; } bool NestedArtboard::worldToLocal(Vec2D world, Vec2D* local) { assert(local != nullptr);
diff --git a/src/shapes/mesh.cpp b/src/shapes/mesh.cpp index 280732b..fd2811e 100644 --- a/src/shapes/mesh.cpp +++ b/src/shapes/mesh.cpp
@@ -92,8 +92,8 @@ } auto factory = artboard()->factory(); - m_UVRenderBuffer = factory->makeBufferF32(toSpan(uv)); - m_IndexRenderBuffer = factory->makeBufferU16(toSpan(*m_IndexBuffer)); + m_UVRenderBuffer = factory->makeBufferF32(uv); + m_IndexRenderBuffer = factory->makeBufferU16(*m_IndexBuffer); } void Mesh::update(ComponentDirt value) { @@ -118,7 +118,7 @@ } auto factory = artboard()->factory(); - m_VertexRenderBuffer = factory->makeBufferF32(toSpan(vertices)); + m_VertexRenderBuffer = factory->makeBufferF32(vertices); } if (skin() == nullptr) {
diff --git a/src/text/line_breaker.cpp b/src/text/line_breaker.cpp index 1cacfa1..5bb7899 100644 --- a/src/text/line_breaker.cpp +++ b/src/text/line_breaker.cpp
@@ -123,7 +123,7 @@ RenderGlyphLine(startRun, startIndex, tailRun, tailIndex, tailRun, tailIndex, startX)); } - ComputeLineSpacing(toSpan(lines), runs); + ComputeLineSpacing(lines, runs); return lines; }
diff --git a/test/rive_file_reader.hpp b/test/rive_file_reader.hpp index 8672edd..bf01652 100644 --- a/test/rive_file_reader.hpp +++ b/test/rive_file_reader.hpp
@@ -28,7 +28,7 @@ fclose(fp); rive::ImportResult result; - auto file = rive::File::import(rive::toSpan(bytes), factory, &result, resolver); + auto file = rive::File::import(bytes, factory, &result, resolver); REQUIRE(result == rive::ImportResult::success); REQUIRE(file.get() != nullptr); REQUIRE(file->artboard() != nullptr);
diff --git a/test/span_test.cpp b/test/span_test.cpp index 6320f84..c4f3f45 100644 --- a/test/span_test.cpp +++ b/test/span_test.cpp
@@ -56,6 +56,6 @@ funcb({array, 4}); std::vector<int> v; - funca(toSpan(v)); - funcb(toSpan(v)); + funca(v); + funcb(v); }
diff --git a/viewer/src/viewer_content/image_content.cpp b/viewer/src/viewer_content/image_content.cpp index 6af8d2a..e9a18f7 100644 --- a/viewer/src/viewer_content/image_content.cpp +++ b/viewer/src/viewer_content/image_content.cpp
@@ -22,7 +22,7 @@ std::unique_ptr<ViewerContent> ViewerContent::Image(const char filename[]) { auto bytes = LoadFile(filename); - auto image = RiveFactory()->decodeImage(rive::toSpan(bytes)); + auto image = RiveFactory()->decodeImage(bytes); if (image) { return std::make_unique<ImageContent>(std::move(image)); }
diff --git a/viewer/src/viewer_content/scene_content.cpp b/viewer/src/viewer_content/scene_content.cpp index a5dc682..1234e6f 100644 --- a/viewer/src/viewer_content/scene_content.cpp +++ b/viewer/src/viewer_content/scene_content.cpp
@@ -280,7 +280,7 @@ std::unique_ptr<ViewerContent> ViewerContent::Scene(const char filename[]) { auto bytes = LoadFile(filename); - if (auto file = rive::File::import(rive::toSpan(bytes), RiveFactory())) { + if (auto file = rive::File::import(bytes, RiveFactory())) { return std::make_unique<SceneContent>(filename, std::move(file)); } return nullptr;
diff --git a/viewer/src/viewer_content/text_content.cpp b/viewer/src/viewer_content/text_content.cpp index 24a9fe2..01190a9 100644 --- a/viewer/src/viewer_content/text_content.cpp +++ b/viewer/src/viewer_content/text_content.cpp
@@ -108,7 +108,7 @@ fclose(fp); assert(bytesRead == size); - gFallbackFont = HBRenderFont::Decode(rive::toSpan(bytes)); + gFallbackFont = HBRenderFont::Decode(bytes); } return gFallbackFont; } @@ -153,7 +153,7 @@ assert(false); return nullptr; } - return fact(rive::toSpan(bytes)); + return fact(bytes); }; const char* fontFiles[] = { @@ -176,7 +176,7 @@ truns.push_back(append(&m_unichars, font1->makeAtCoord(c1), 30, " that often")); truns.push_back(append(&m_unichars, font0, 30, " lies the head.")); - m_breaks = compute_word_breaks(rive::toSpan(m_unichars)); + m_breaks = compute_word_breaks(m_unichars); return truns; } @@ -184,7 +184,7 @@ public: TextContent() { auto truns = this->make_truns(ViewerContent::DecodeFont); - m_gruns.push_back(truns[0].font->shapeText(rive::toSpan(m_unichars), rive::toSpan(truns))); + m_gruns.push_back(truns[0].font->shapeText(m_unichars, truns)); m_xform = rive::Mat2D::fromTranslate(10, 0) * rive::Mat2D::fromScale(3, 3); } @@ -193,10 +193,9 @@ renderer->save(); renderer->transform(m_xform); - auto lines = - rive::RenderGlyphLine::BreakLines(rive::toSpan(gruns), rive::toSpan(m_breaks), width); + auto lines = rive::RenderGlyphLine::BreakLines(gruns, m_breaks, width); - drawpara(RiveFactory(), renderer, rive::toSpan(lines), rive::toSpan(gruns), {0, 0}); + drawpara(RiveFactory(), renderer, lines, gruns, {0, 0}); draw_line(RiveFactory(), renderer, width); renderer->restore();
diff --git a/viewer/src/viewer_content/textpath_content.cpp b/viewer/src/viewer_content/textpath_content.cpp index 2aeda05..80856d8 100644 --- a/viewer/src/viewer_content/textpath_content.cpp +++ b/viewer/src/viewer_content/textpath_content.cpp
@@ -121,7 +121,7 @@ assert(false); return nullptr; } - return fact(toSpan(bytes)); + return fact(bytes); }; const char* fontFiles[] = { @@ -163,7 +163,7 @@ auto truns = this->make_truns(ViewerContent::DecodeFont); - m_gruns = truns[0].font->shapeText(toSpan(m_unichars), toSpan(truns)); + m_gruns = truns[0].font->shapeText(m_unichars, truns); m_gbounds = compute_bounds(m_gruns); m_oneLineXform = Mat2D::fromScale(2.5, 2.5) * Mat2D::fromTranslate(20, 80); @@ -212,7 +212,7 @@ renderer->save(); renderer->transform(m_trans); - RawPath warp = make_quad_path(toSpan(m_pathpts)); + RawPath warp = make_quad_path(m_pathpts); this->draw_warp(renderer, warp); auto meas = ContourMeasureIter(warp).next();
diff --git a/viewer/src/viewer_content/trimpath_content.cpp b/viewer/src/viewer_content/trimpath_content.cpp index fc7318a..89c9bb9 100644 --- a/viewer/src/viewer_content/trimpath_content.cpp +++ b/viewer/src/viewer_content/trimpath_content.cpp
@@ -85,7 +85,7 @@ } void handleDraw(rive::Renderer* renderer, double) override { - auto path = make_quad_path(toSpan(m_pathpts)); + auto path = make_quad_path(m_pathpts); RawPath cubicpath; cubicpath.move(m_pathpts[0]);