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

Code before:
	_FORCE_INLINE_ operator Span<T>() const { return _cowdata.span(); }
	_FORCE_INLINE_ Span<T> span() const { return _cowdata.span(); }

	_FORCE_INLINE_ void clear() { resize(0); }
	_FORCE_INLINE_ bool is_empty() const { return _cowdata.is_empty(); }

	_FORCE_INLINE_ T get(Size p_index) { return _cowdata.get(p_index); }
	_FORCE_INLINE_ const T &get(Size p_index) const { return _cowdata.get(p_index); }
	_FORCE_INLINE_ void set(Size p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); }
	Error resize(Size p_size) { return _cowdata.resize(p_size); }
	Error resize_zeroed(Size p_size) { return _cowdata.template resize<true>(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 find_seq(const Vector<T> &p_vector, Size p_from = 0) const {
		if (p_from < 0) {
			p_from = size() + p_from;
		}
		if (p_from < 0 || p_from >= size()) {
			return -1; // Still out of bounds
		}
		if (p_vector.size() == 0 || size() == 0 || p_vector.size() > size()) {
			return -1; // Won't find anything!
		}

		if (p_vector.size() == 1) {
			// Optimize with single-char implementation.
			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 {
		if (p_from < 0) {
			p_from = size() + p_from;
		}
		if (p_from < 0 || p_from >= size()) {
			return -1;
		}

Review comment (suggestion):
The name `find_sequence` would be better than `find_seq`. This is not a super common function so it should not be shortened.

Code after:
	_FORCE_INLINE_ Span<T> span() const { return _cowdata.span(); }

	_FORCE_INLINE_ void clear() { _cowdata.clear(); }
	_FORCE_INLINE_ bool is_empty() const { return _cowdata.is_empty(); }

	_FORCE_INLINE_ T get(Size p_index) { return _cowdata.get(p_index); }
	_FORCE_INLINE_ const T &get(Size p_index) const { return _cowdata.get(p_index); }
	_FORCE_INLINE_ void set(Size p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); }

	/// Resize the vector.
	/// Elements are initialized (or not) depending on what the default C++ behavior for this type is.
	_FORCE_INLINE_ Error resize(Size p_size) {
		return _cowdata.template resize<!std::is_trivially_constructible_v<T>>(p_size);
	}

	/// Resize and set all values to 0 / false / nullptr.
	/// This is only available for zero constructible types.
	_FORCE_INLINE_ Error resize_initialized(Size p_size) {
		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); }