Removed unneeded copies

This commit is contained in:
Krystian Stasiowski
2019-10-27 16:26:49 -04:00
parent b8695d8644
commit 9156aa8ec8
2 changed files with 13 additions and 22 deletions

View File

@ -1518,10 +1518,8 @@ public:
const T& t, const T& t,
size_type pos = 0) const size_type pos = 0) const
{ {
return string_view_type( string_view_type sv = t;
*this).find( return find(sv.data(), pos, sv.size());
t, pos);
} }
#endif #endif
@ -1585,9 +1583,8 @@ public:
const T& t, const T& t,
size_type pos = npos) const size_type pos = npos) const
{ {
return string_view_type( string_view_type sv = t;
*this).rfind( return rfind(sv.data(), pos, sv.size());
t, pos);
} }
#endif #endif
@ -1650,9 +1647,8 @@ public:
const T& t, const T& t,
size_type pos = 0) const size_type pos = 0) const
{ {
return string_view_type( string_view_type sv = t;
*this).find_first_of( return find_first_of(sv.data(), pos, sv.size());
t, pos);
} }
#endif #endif
@ -1715,9 +1711,8 @@ public:
const T& t, const T& t,
size_type pos = npos) const size_type pos = npos) const
{ {
return string_view_type( string_view_type sv = t;
*this).find_last_of( return find_last_of(sv.data(), pos, sv.size());
t, pos);
} }
#endif #endif
@ -1780,9 +1775,8 @@ public:
const T& t, const T& t,
size_type pos = 0) const size_type pos = 0) const
{ {
return string_view_type( string_view_type sv = t;
*this).find_first_not_of( return find_first_not_of(sv.data(), pos, sv.size());
t, pos);
} }
#endif #endif
@ -1845,9 +1839,8 @@ public:
const T& t, const T& t,
size_type pos = npos) const size_type pos = npos) const
{ {
return string_view_type( string_view_type sv = t;
*this).find_last_not_of( return find_last_not_of(sv.data(), pos, sv.size());
t, pos);
} }
#endif #endif

View File

@ -667,12 +667,10 @@ find(
size_type n) const -> size_type n) const ->
size_type size_type
{ {
if (pos > n_) if (pos > n_ || n > n_ - pos)
return npos; return npos;
if (!n) if (!n)
return pos; return pos;
if (n > n_ - pos)
return npos;
const auto res = std::search(&s_[pos], &s_[n_], s, &s[n], Traits::eq); const auto res = std::search(&s_[pos], &s_[n_], s, &s[n], Traits::eq);
return res == end() ? npos : std::distance(s_, res); return res == end() ? npos : std::distance(s_, res);
} }