Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

`Vector` & `LocalVector` ordered_insert uses binary search

lawnjellyd2e4fb43a07f
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h
index 4da8977855b..85d84117962 100644
--- a/core/templates/local_vector.h
+++ b/core/templates/local_vector.h
@@ -314,13 +314,8 @@ public:
}
void ordered_insert(T p_val) {
- U i;
- for (i = 0; i < count; i++) {
- if (p_val < data[i]) {
- break;
- }
- }
- insert(i, p_val);
+ U idx = span().bisect(p_val, false);
+ insert(idx, std::move(p_val));
}
Vector<uint8_t> to_byte_array() const { //useful to pass stuff to gpu or variant
diff --git a/core/templates/vector.h b/core/templates/vector.h
index 251c4d7059b..f0a8773ef06 100644
--- a/core/templates/vector.h
+++ b/core/templates/vector.h
@@ -200,13 +200,8 @@ public:
}
void ordered_insert(const T &p_val) {
- Size i;
- for (i = 0; i < _cowdata.size(); i++) {
- if (p_val < operator[](i)) {
- break;
- }
- }
- insert(i, p_val);
+ int idx = span().bisect(p_val, false);
+ insert(idx, p_val);
}
void operator=(const Vector &p_from) { _cowdata = p_from._cowdata; }