BAN: StringView::Split() now precomputes number of elements

We dont have to resize vector on PushBack()'s if we reserve required size
This commit is contained in:
Bananymous
2022-12-20 11:37:28 +02:00
parent d5a068f90c
commit 4c559f50a4
4 changed files with 22 additions and 3 deletions

View File

@@ -40,6 +40,7 @@ class ErrorOr
public:
ErrorOr(const T& value) : m_has_error(false) { m_data = (void*)new T(value); }
ErrorOr(const Error& error) : m_has_error(true) { m_data = (void*)new Error(error); }
template<typename S> ErrorOr(const ErrorOr<S>& other) : ErrorOr(other.GetError()) {}
~ErrorOr() { IsError() ? (delete reinterpret_cast<Error*>(m_data)) : (delete reinterpret_cast<T*>(m_data)); }
bool IsError() const { return m_has_error; }

View File

@@ -24,7 +24,7 @@ namespace BAN
StringView Substring(size_type, size_type = -1) const;
Vector<StringView> Split(char, bool = false);
ErrorOr<Vector<StringView>> Split(char, bool = false);
size_type Count(char) const;