Update debian/patches/0001-Bezier-Opti.patch
This commit is contained in:
parent
2c14356f3b
commit
f5816a6d77
25
debian/patches/0001-Bezier-Opti.patch
vendored
25
debian/patches/0001-Bezier-Opti.patch
vendored
@ -1,4 +1,4 @@
|
|||||||
From 3b7208caffa1362e43eff57d58b86d38e484193b Mon Sep 17 00:00:00 2001
|
From a5fff93908a78740c17a7e5edccc01ad0edda5c5 Mon Sep 17 00:00:00 2001
|
||||||
From: Tom Englund <tomenglund26@gmail.com>
|
From: Tom Englund <tomenglund26@gmail.com>
|
||||||
Date: Tue, 19 Nov 2024 18:46:03 +0100
|
Date: Tue, 19 Nov 2024 18:46:03 +0100
|
||||||
Subject: [PATCH] bezier: optimize setup of bezier curves
|
Subject: [PATCH] bezier: optimize setup of bezier curves
|
||||||
@ -15,15 +15,15 @@ references where we can.
|
|||||||
these changes we are now down to an average of "time to bake: 2.50µs."
|
these changes we are now down to an average of "time to bake: 2.50µs."
|
||||||
on my machine compared to before average of "time to bake: 11.15µs"
|
on my machine compared to before average of "time to bake: 11.15µs"
|
||||||
---
|
---
|
||||||
src/helpers/BezierCurve.cpp | 35 ++++++++++++++++++++---------------
|
src/helpers/BezierCurve.cpp | 39 ++++++++++++++++++++++++-------------
|
||||||
src/helpers/BezierCurve.hpp | 8 ++++----
|
src/helpers/BezierCurve.hpp | 8 ++++----
|
||||||
2 files changed, 24 insertions(+), 19 deletions(-)
|
2 files changed, 29 insertions(+), 18 deletions(-)
|
||||||
|
|
||||||
diff --git a/src/helpers/BezierCurve.cpp b/src/helpers/BezierCurve.cpp
|
diff --git a/src/helpers/BezierCurve.cpp b/src/helpers/BezierCurve.cpp
|
||||||
index ea567ad61ca..0ef0883f805 100644
|
index ea567ad61ca..23fcd691f24 100644
|
||||||
--- a/src/helpers/BezierCurve.cpp
|
--- a/src/helpers/BezierCurve.cpp
|
||||||
+++ b/src/helpers/BezierCurve.cpp
|
+++ b/src/helpers/BezierCurve.cpp
|
||||||
@@ -6,24 +6,21 @@
|
@@ -6,24 +6,27 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
void CBezierCurve::setup(std::vector<Vector2D>* pVec) {
|
void CBezierCurve::setup(std::vector<Vector2D>* pVec) {
|
||||||
@ -35,13 +35,18 @@ index ea567ad61ca..0ef0883f805 100644
|
|||||||
-
|
-
|
||||||
- for (auto const& p : *pVec) {
|
- for (auto const& p : *pVec) {
|
||||||
- m_dPoints.push_back(p);
|
- m_dPoints.push_back(p);
|
||||||
- }
|
|
||||||
-
|
|
||||||
- m_dPoints.emplace_back(Vector2D(1, 1));
|
|
||||||
+ // Avoid reallocations by reserving enough memory upfront
|
+ // Avoid reallocations by reserving enough memory upfront
|
||||||
+ m_dPoints.resize(pVec->size() + 2);
|
+ m_dPoints.resize(pVec->size() + 2);
|
||||||
+ m_dPoints[0] = Vector2D(0, 0); // Start point
|
+ m_dPoints[0] = Vector2D(0, 0); // Start point
|
||||||
+ std::copy(pVec->begin(), pVec->end(), m_dPoints.begin() + 1);
|
+ size_t index = 1; // Start after the first element
|
||||||
|
+ for (const auto& vec : *pVec) {
|
||||||
|
+ if (index < m_dPoints.size() - 1) { // Bounds check to ensure safety
|
||||||
|
+ m_dPoints[index] = vec;
|
||||||
|
+ ++index;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
-
|
||||||
|
- m_dPoints.emplace_back(Vector2D(1, 1));
|
||||||
+ m_dPoints.back() = Vector2D(1, 1); // End point
|
+ m_dPoints.back() = Vector2D(1, 1); // End point
|
||||||
|
|
||||||
RASSERT(m_dPoints.size() == 4, "CBezierCurve only supports cubic beziers! (points num: {})", m_dPoints.size());
|
RASSERT(m_dPoints.size() == 4, "CBezierCurve only supports cubic beziers! (points num: {})", m_dPoints.size());
|
||||||
@ -55,7 +60,7 @@ index ea567ad61ca..0ef0883f805 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto ELAPSEDUS = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - BEGIN).count() / 1000.f;
|
const auto ELAPSEDUS = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - BEGIN).count() / 1000.f;
|
||||||
@@ -40,18 +37,26 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) {
|
@@ -40,18 +43,26 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) {
|
||||||
ELAPSEDUS, ELAPSEDCALCAVG);
|
ELAPSEDUS, ELAPSEDCALCAVG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user