Skip to content

Optimize find in Array and CowData #84595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions core/templates/cowdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,16 @@ Error CowData<T>::resize(int p_size) {

template <class T>
int CowData<T>::find(const T &p_val, int p_from) const {
int ret = -1;

if (p_from < 0 || size() == 0) {
return ret;
return -1;
}

for (int i = p_from; i < size(); i++) {
if (get(i) == p_val) {
ret = i;
break;
return i;
}
}

return ret;
return -1;
}

template <class T>
Expand Down
10 changes: 3 additions & 7 deletions core/variant/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,16 @@ int Array::find(const Variant &p_value, int p_from) const {
Variant value = p_value;
ERR_FAIL_COND_V(!_p->typed.validate(value, "find"), -1);

int ret = -1;

if (p_from < 0 || size() == 0) {
return ret;
return -1;
}

for (int i = p_from; i < size(); i++) {
if (StringLikeVariantComparator::compare(_p->array[i], value)) {
ret = i;
break;
return i;
}
}

return ret;
return -1;
}

int Array::rfind(const Variant &p_value, int p_from) const {
Expand Down