Skip to content

Commit 1169812

Browse files
committed
util/StringBuilder: add UnsafeAppend()
For callers which have already checked CanAppend().
1 parent 34b1053 commit 1169812

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/util/StringBuilder.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
template<typename T>
99
void
10-
BasicStringBuilder<T>::Append(std::basic_string_view<T> src)
10+
BasicStringBuilder<T>::UnsafeAppend(std::basic_string_view<T> src) noexcept
1111
{
12-
CheckAppend(src.size());
1312
p = std::copy(src.begin(), src.end(), p);
1413
*p = SENTINEL;
1514
}

src/util/StringBuilder.hxx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,26 @@ public:
6363
throw TooLargeError{};
6464
}
6565

66-
constexpr void Append(T ch) {
67-
CheckAppend(1);
68-
66+
constexpr void UnsafeAppend(T ch) noexcept {
6967
*p++ = ch;
7068
*p = SENTINEL;
7169
}
7270

73-
void Append(std::basic_string_view<T> src);
71+
constexpr void Append(T ch) {
72+
CheckAppend(1);
73+
UnsafeAppend(ch);
74+
}
75+
76+
/**
77+
* Like Append(), but do not check whether there is enough
78+
* space in the buffer.
79+
*/
80+
void UnsafeAppend(std::basic_string_view<T> src) noexcept;
81+
82+
void Append(std::basic_string_view<T> src) {
83+
CheckAppend(src.size());
84+
UnsafeAppend(src);
85+
}
7486
};
7587

7688
class StringBuilder : public BasicStringBuilder<char> {

0 commit comments

Comments
 (0)