Skip to content

Commit d5c29e3

Browse files
authored
Merge branch 'branch-25.04' into cln/dtype/more_utils
2 parents 0537bbd + 93d98af commit d5c29e3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cpp/include/cudf/strings/string_view.cuh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,12 @@ __device__ inline size_type string_view::rfind(char_utf8 chr, size_type pos, siz
443443
__device__ inline string_view string_view::substr(size_type pos, size_type count) const
444444
{
445445
if (pos < 0 || pos >= length()) { return string_view{}; }
446-
auto const itr = begin() + pos;
447-
auto const spos = itr.byte_offset();
448-
auto const epos = count >= 0 ? (itr + count).byte_offset() : size_bytes();
449-
return {data() + spos, epos - spos};
446+
auto const spos = begin() + pos;
447+
auto const epos = count >= 0 ? (spos + count) : const_iterator{*this, _length, size_bytes()};
448+
auto ss = string_view{data() + spos.byte_offset(), epos.byte_offset() - spos.byte_offset()};
449+
// this potentially saves redundant character counting downstream
450+
if (_length != UNKNOWN_STRING_LENGTH) { ss._length = epos.position() - spos.position(); }
451+
return ss;
450452
}
451453

452454
__device__ inline size_type string_view::character_offset(size_type bytepos) const

0 commit comments

Comments
 (0)