Repository: godotengine/godot
File: core/templates/vector.h (C/C++)

Code before:
		}
		if (p_vector.size() == 0 || size() == 0 || p_vector.size() > size()) {
			return -1; // won't find anything!
		}
	
		if (p_vector.size() == 1){
			return span().find(p_vector[0], p_from);
		}

		return span().find_seq(p_vector.span(), p_from); 
	}
	Size rfind(const T &p_val, Size p_from = -1) const { return span().rfind(p_val, p_from); }
	Size rfind_seq(const Vector<T> &p_vector, Size p_from = 0) const {
		if (p_vector.size() == 0 || p_vector.size() > size()){
			return -1;
		}
	
		if (p_vector.size() == 1){
			return span().rfind(p_vector[0], p_from);
		}
	
		if (p_from < 0) {
			p_from = size() + p_from;
		}
		if (p_from < 0 || p_from >= size()) {
			p_from = size() - 1;
		}
		if (p_from > size() - p_vector.size()){
			p_from = size() - p_vector.size();
		}
		
		return span().rfind_seq(p_vector.span(), p_from); 
	}
	Size count(const T &p_val) const { return span().count(p_val); }

	// Must take a copy instead of a reference (see GH-31736).
	void append_array(Vector<T> p_other);

	_FORCE_INLINE_ bool has(const T &p_val) const { return find(p_val) != -1; }

	void sort() {
		sort_custom<_DefaultComparator<T>>();
	}

	template <typename Comparator, bool Validate = SORT_ARRAY_VALIDATE_ENABLED, typename... Args>
	void sort_custom(Args &&...args) {
		Size len = _cowdata.size();
		if (len == 0) {
			return;
		}


Review comment (suggestion):
I think it would be good to follow along with https://github.com/godotengine/godot/pull/104286/ and harmonize boundary logic (explained in my general comment):
```suggestion
			return -1;
```


Code after:
		return _cowdata.template resize<true>(p_size);
	}

	/// Resize and set all values to 0 / false / nullptr.
	/// This is only available for trivially destructible types (otherwise, trivial resize might be UB).
	_FORCE_INLINE_ Error resize_uninitialized(Size p_size) {
		// resize() statically asserts that T is compatible, no need to do it ourselves.
		return _cowdata.template resize<false>(p_size);
	}

	_FORCE_INLINE_ const T &operator[](Size p_index) const { return _cowdata.get(p_index); }
	// Must take a copy instead of a reference (see GH-31736).
	Error insert(Size p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); }
	Size find(const T &p_val, Size p_from = 0) const {
		if (p_from < 0) {
			p_from = size() + p_from;
		}
		if (p_from < 0 || p_from >= size()) {
			return -1;
		}
		return span().find(p_val, p_from);
	}
	Size rfind(const T &p_val, Size p_from = -1) const {
		if (p_from < 0) {
			p_from = size() + p_from;
		}
		if (p_from < 0 || p_from >= size()) {
			return -1;
		}
		return span().rfind(p_val, p_from);
	}
	Size count(const T &p_val) const { return span().count(p_val); }

	// Must take a copy instead of a reference (see GH-31736).
	void append_array(Vector<T> p_other);

	_FORCE_INLINE_ bool has(const T &p_val) const { return find(p_val) != -1; }

	void sort() {
		sort_custom<Comparator<T>>();
	}

	template <typename Comparator, bool Validate = SORT_ARRAY_VALIDATE_ENABLED, typename... Args>
	void sort_custom(Args &&...args) {
		Size len = _cowdata.size();
		if (len == 0) {
			return;
		}

		T *data = ptrw();
		SortArray<T, Comparator, Validate> sorter{ args... };