Skip to content

Commit

Permalink
Merge pull request #50139 from LightningAA/rename-remove-to-remove-at
Browse files Browse the repository at this point in the history
Rename `remove()` to `remove_at()` when removing by index
  • Loading branch information
akien-mga authored Nov 24, 2021
2 parents 5efe80f + e078f97 commit 96e70ac
Show file tree
Hide file tree
Showing 134 changed files with 323 additions and 323 deletions.
2 changes: 1 addition & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
void Input::remove_joy_mapping(String p_guid) {
for (int i = map_db.size() - 1; i >= 0; i--) {
if (p_guid == map_db[i].uid) {
map_db.remove(i);
map_db.remove_at(i);
}
}
for (KeyValue<int, Joypad> &E : joy_names) {
Expand Down
4 changes: 2 additions & 2 deletions core/math/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
}

sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
open_list.remove(open_list.size() - 1);
open_list.remove_at(open_list.size() - 1);
p->closed_pass = pass; // Mark the point as closed

for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
Expand Down Expand Up @@ -812,7 +812,7 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
}

sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
open_list.remove(open_list.size() - 1);
open_list.remove_at(open_list.size() - 1);
p->closed_pass = astar.pass; // Mark the point as closed

for (OAHashMap<int, AStar::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
Expand Down
2 changes: 1 addition & 1 deletion core/math/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class BVH_Manager {
// remove from changed items (not very efficient yet)
for (int n = 0; n < (int)changed_items.size(); n++) {
if (changed_items[n] == p_handle) {
changed_items.remove_unordered(n);
changed_items.remove_at_unordered(n);

// because we are using an unordered remove,
// the last changed item will now be at spot 'n',
Expand Down
2 changes: 1 addition & 1 deletion core/math/bvh_pair.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct ItemPairs {
for (int n = 0; n < num_pairs; n++) {
if (extended_pairs[n].handle == h) {
userdata = extended_pairs[n].userdata;
extended_pairs.remove_unordered(n);
extended_pairs.remove_at_unordered(n);
num_pairs--;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion core/math/convex_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ real_t ConvexHullInternal::shrink(real_t p_amount, real_t p_clamp_amount) {

while (stack.size() > 0) {
Vertex *v = stack[stack.size() - 1];
stack.remove(stack.size() - 1);
stack.remove_at(stack.size() - 1);
Edge *e = v->edges;
if (e) {
do {
Expand Down
4 changes: 2 additions & 2 deletions core/math/delaunay_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Delaunay2D {

for (int j = 0; j < triangles.size(); j++) {
if (triangles[j].bad) {
triangles.remove(j);
triangles.remove_at(j);
j--;
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ class Delaunay2D {
}
}
if (invalid) {
triangles.remove(i);
triangles.remove_at(i);
i--;
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/math/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ Expression::ENode *Expression::_parse_expression() {
op->nodes[1] = nullptr;
expression.write[i].is_op = false;
expression.write[i].node = op;
expression.remove(i + 1);
expression.remove_at(i + 1);
}

} else {
Expand Down Expand Up @@ -1119,8 +1119,8 @@ Expression::ENode *Expression::_parse_expression() {

//replace all 3 nodes by this operator and make it an expression
expression.write[next_op - 1].node = op;
expression.remove(next_op);
expression.remove(next_op);
expression.remove_at(next_op);
expression.remove_at(next_op);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/object/undo_redo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void UndoRedo::_pop_history_tail() {
}
}

actions.remove(0);
actions.remove_at(0);
if (current_action >= 0) {
current_action--;
}
Expand Down
6 changes: 3 additions & 3 deletions core/string/node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ void NodePath::simplify() {
break;
}
if (data->path[i].operator String() == ".") {
data->path.remove(i);
data->path.remove_at(i);
i--;
} else if (i > 0 && data->path[i].operator String() == ".." && data->path[i - 1].operator String() != "." && data->path[i - 1].operator String() != "..") {
//remove both
data->path.remove(i - 1);
data->path.remove(i - 1);
data->path.remove_at(i - 1);
data->path.remove_at(i - 1);
i -= 2;
if (data->path.size() == 0) {
data->path.push_back(".");
Expand Down
8 changes: 4 additions & 4 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3670,15 +3670,15 @@ String String::simplify_path() const {
for (int i = 0; i < dirs.size(); i++) {
String d = dirs[i];
if (d == ".") {
dirs.remove(i);
dirs.remove_at(i);
i--;
} else if (d == "..") {
if (i == 0) {
dirs.remove(i);
dirs.remove_at(i);
i--;
} else {
dirs.remove(i);
dirs.remove(i - 1);
dirs.remove_at(i);
dirs.remove_at(i - 1);
i -= 2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/string/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class String {
_FORCE_INLINE_ char32_t *ptrw() { return _cowdata.ptrw(); }
_FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }

void remove(int p_index) { _cowdata.remove(p_index); }
void remove_at(int p_index) { _cowdata.remove_at(p_index); }

_FORCE_INLINE_ void clear() { resize(0); }

Expand Down
2 changes: 1 addition & 1 deletion core/templates/bin_sorted_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BinSortedArray {
return current_idx;
}

void remove(uint64_t p_idx) {
void remove_at(uint64_t p_idx) {
ERR_FAIL_COND(p_idx >= array.size());
uint64_t new_idx = move(p_idx, 0);
uint64_t swap_idx = array.size() - 1;
Expand Down
2 changes: 1 addition & 1 deletion core/templates/cowdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class CowData {

Error resize(int p_size);

_FORCE_INLINE_ void remove(int p_index) {
_FORCE_INLINE_ void remove_at(int p_index) {
ERR_FAIL_INDEX(p_index, size());
T *p = ptrw();
int len = size();
Expand Down
6 changes: 3 additions & 3 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LocalVector {
}
}

void remove(U p_index) {
void remove_at(U p_index) {
ERR_FAIL_UNSIGNED_INDEX(p_index, count);
count--;
for (U i = p_index; i < count; i++) {
Expand All @@ -83,7 +83,7 @@ class LocalVector {

/// Removes the item copying the last value into the position of the one to
/// remove. It's generally faster than `remove`.
void remove_unordered(U p_index) {
void remove_at_unordered(U p_index) {
ERR_FAIL_INDEX(p_index, count);
count--;
if (count > p_index) {
Expand All @@ -97,7 +97,7 @@ class LocalVector {
void erase(const T &p_val) {
int64_t idx = find(p_val);
if (idx >= 0) {
remove(idx);
remove_at(idx);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/templates/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class Vector {
_FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias
void fill(T p_elem);

void remove(int p_index) { _cowdata.remove(p_index); }
void remove_at(int p_index) { _cowdata.remove_at(p_index); }
void erase(const T &p_val) {
int idx = find(p_val);
if (idx >= 0) {
remove(idx);
remove_at(idx);
}
}
void reverse();
Expand Down
2 changes: 1 addition & 1 deletion core/templates/vmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class VMap {
if (pos < 0) {
return;
}
_cowdata.remove(pos);
_cowdata.remove_at(pos);
}

int find(const T &p_val) const {
Expand Down
2 changes: 1 addition & 1 deletion core/templates/vset.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class VSet {
if (pos < 0) {
return;
}
_data.remove(pos);
_data.remove_at(pos);
}

int find(const T &p_val) const {
Expand Down
8 changes: 4 additions & 4 deletions core/variant/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ bool Array::has(const Variant &p_value) const {
return _p->array.find(p_value, 0) != -1;
}

void Array::remove(int p_pos) {
_p->array.remove(p_pos);
void Array::remove_at(int p_pos) {
_p->array.remove_at(p_pos);
}

void Array::set(int p_idx, const Variant &p_value) {
Expand Down Expand Up @@ -576,7 +576,7 @@ Variant Array::pop_back() {
Variant Array::pop_front() {
if (!_p->array.is_empty()) {
const Variant ret = _p->array.get(0);
_p->array.remove(0);
_p->array.remove_at(0);
return ret;
}
return Variant();
Expand All @@ -603,7 +603,7 @@ Variant Array::pop_at(int p_pos) {
_p->array.size()));

const Variant ret = _p->array.get(p_pos);
_p->array.remove(p_pos);
_p->array.remove_at(p_pos);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion core/variant/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Array {
Error resize(int p_new_size);

Error insert(int p_pos, const Variant &p_value);
void remove(int p_pos);
void remove_at(int p_pos);
void fill(const Variant &p_value);

Variant front() const;
Expand Down
20 changes: 10 additions & 10 deletions core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ static void _register_variant_builtin_methods() {
bind_method(Array, append_array, sarray("array"), varray());
bind_method(Array, resize, sarray("size"), varray());
bind_method(Array, insert, sarray("position", "value"), varray());
bind_method(Array, remove, sarray("position"), varray());
bind_method(Array, remove_at, sarray("position"), varray());
bind_method(Array, fill, sarray("value"), varray());
bind_method(Array, erase, sarray("value"), varray());
bind_method(Array, front, sarray(), varray());
Expand Down Expand Up @@ -1842,7 +1842,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedByteArray, push_back, sarray("value"), varray());
bind_method(PackedByteArray, append, sarray("value"), varray());
bind_method(PackedByteArray, append_array, sarray("array"), varray());
bind_method(PackedByteArray, remove, sarray("index"), varray());
bind_method(PackedByteArray, remove_at, sarray("index"), varray());
bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray());
bind_method(PackedByteArray, fill, sarray("value"), varray());
bind_method(PackedByteArray, resize, sarray("new_size"), varray());
Expand Down Expand Up @@ -1903,7 +1903,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedInt32Array, push_back, sarray("value"), varray());
bind_method(PackedInt32Array, append, sarray("value"), varray());
bind_method(PackedInt32Array, append_array, sarray("array"), varray());
bind_method(PackedInt32Array, remove, sarray("index"), varray());
bind_method(PackedInt32Array, remove_at, sarray("index"), varray());
bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedInt32Array, fill, sarray("value"), varray());
bind_method(PackedInt32Array, resize, sarray("new_size"), varray());
Expand All @@ -1923,7 +1923,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedInt64Array, push_back, sarray("value"), varray());
bind_method(PackedInt64Array, append, sarray("value"), varray());
bind_method(PackedInt64Array, append_array, sarray("array"), varray());
bind_method(PackedInt64Array, remove, sarray("index"), varray());
bind_method(PackedInt64Array, remove_at, sarray("index"), varray());
bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedInt64Array, fill, sarray("value"), varray());
bind_method(PackedInt64Array, resize, sarray("new_size"), varray());
Expand All @@ -1943,7 +1943,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedFloat32Array, push_back, sarray("value"), varray());
bind_method(PackedFloat32Array, append, sarray("value"), varray());
bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
bind_method(PackedFloat32Array, remove, sarray("index"), varray());
bind_method(PackedFloat32Array, remove_at, sarray("index"), varray());
bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedFloat32Array, fill, sarray("value"), varray());
bind_method(PackedFloat32Array, resize, sarray("new_size"), varray());
Expand All @@ -1963,7 +1963,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedFloat64Array, push_back, sarray("value"), varray());
bind_method(PackedFloat64Array, append, sarray("value"), varray());
bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
bind_method(PackedFloat64Array, remove, sarray("index"), varray());
bind_method(PackedFloat64Array, remove_at, sarray("index"), varray());
bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedFloat64Array, fill, sarray("value"), varray());
bind_method(PackedFloat64Array, resize, sarray("new_size"), varray());
Expand All @@ -1983,7 +1983,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedStringArray, push_back, sarray("value"), varray());
bind_method(PackedStringArray, append, sarray("value"), varray());
bind_method(PackedStringArray, append_array, sarray("array"), varray());
bind_method(PackedStringArray, remove, sarray("index"), varray());
bind_method(PackedStringArray, remove_at, sarray("index"), varray());
bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
bind_method(PackedStringArray, fill, sarray("value"), varray());
bind_method(PackedStringArray, resize, sarray("new_size"), varray());
Expand All @@ -2003,7 +2003,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector2Array, push_back, sarray("value"), varray());
bind_method(PackedVector2Array, append, sarray("value"), varray());
bind_method(PackedVector2Array, append_array, sarray("array"), varray());
bind_method(PackedVector2Array, remove, sarray("index"), varray());
bind_method(PackedVector2Array, remove_at, sarray("index"), varray());
bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedVector2Array, fill, sarray("value"), varray());
bind_method(PackedVector2Array, resize, sarray("new_size"), varray());
Expand All @@ -2023,7 +2023,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector3Array, push_back, sarray("value"), varray());
bind_method(PackedVector3Array, append, sarray("value"), varray());
bind_method(PackedVector3Array, append_array, sarray("array"), varray());
bind_method(PackedVector3Array, remove, sarray("index"), varray());
bind_method(PackedVector3Array, remove_at, sarray("index"), varray());
bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
bind_method(PackedVector3Array, fill, sarray("value"), varray());
bind_method(PackedVector3Array, resize, sarray("new_size"), varray());
Expand All @@ -2043,7 +2043,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedColorArray, push_back, sarray("value"), varray());
bind_method(PackedColorArray, append, sarray("value"), varray());
bind_method(PackedColorArray, append_array, sarray("array"), varray());
bind_method(PackedColorArray, remove, sarray("index"), varray());
bind_method(PackedColorArray, remove_at, sarray("index"), varray());
bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
bind_method(PackedColorArray, fill, sarray("value"), varray());
bind_method(PackedColorArray, resize, sarray("new_size"), varray());
Expand Down
6 changes: 3 additions & 3 deletions core/variant/variant_setget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ struct VariantIndexedSetGet_String {
String *b = VariantGetInternalPtr<String>::get_ptr(base);
const String *v = VariantInternal::get_string(value);
if (v->length() == 0) {
b->remove(index);
b->remove_at(index);
} else {
b->set(index, v->get(0));
}
Expand All @@ -723,7 +723,7 @@ struct VariantIndexedSetGet_String {
String *b = VariantGetInternalPtr<String>::get_ptr(base);
const String *v = VariantInternal::get_string(value);
if (v->length() == 0) {
b->remove(index);
b->remove_at(index);
} else {
b->set(index, v->get(0));
}
Expand All @@ -738,7 +738,7 @@ struct VariantIndexedSetGet_String {
OOB_TEST(index, v.length());
const String &m = *reinterpret_cast<const String *>(member);
if (unlikely(m.length() == 0)) {
v.remove(index);
v.remove_at(index);
} else {
v.set(index, m.unicode_at(0));
}
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
<return type="void" />
<argument index="0" name="value" type="Variant" />
<description>
Removes the first occurrence of a value from the array. To remove an element by index, use [method remove] instead.
Removes the first occurrence of a value from the array. To remove an element by index, use [method remove_at] instead.
[b]Note:[/b] This method acts in-place and doesn't return a value.
[b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
</description>
Expand Down Expand Up @@ -400,7 +400,7 @@
[/codeblock]
</description>
</method>
<method name="remove">
<method name="remove_at">
<return type="void" />
<argument index="0" name="position" type="int" />
<description>
Expand Down
Loading

0 comments on commit 96e70ac

Please sign in to comment.