Skip to content

Commit 8561c23

Browse files
committed
Move some String constructors out of the header
Those do not really need to get inlined and pull std::max which really wants <algorithm> which is an expensive header.
1 parent bc9dd1a commit 8561c23

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/string.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ void String::Data::clear()
118118
set_empty();
119119
}
120120

121+
String::String(Codepoint cp, CharCount count)
122+
{
123+
reserve(utf8::codepoint_size(cp) * (int)count);
124+
while (count-- > 0)
125+
utf8::dump(std::back_inserter(*this), cp);
126+
}
127+
128+
String::String(Codepoint cp, ColumnCount count)
129+
{
130+
int cp_count = (int)(count / max(codepoint_width(cp), 1_col));
131+
reserve(utf8::codepoint_size(cp) * cp_count);
132+
while (cp_count-- > 0)
133+
utf8::dump(std::back_inserter(*this), cp);
134+
}
135+
121136
void String::resize(ByteCount size, char c)
122137
{
123138
const size_t target_size = (size_t)size;

src/string.hh

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,9 @@ public:
109109
String() {}
110110
String(const char* content) : m_data(content, (size_t)strlen(content)) {}
111111
String(const char* content, ByteCount len) : m_data(content, (size_t)len) {}
112-
explicit String(Codepoint cp, CharCount count = 1)
113-
{
114-
reserve(utf8::codepoint_size(cp) * (int)count);
115-
while (count-- > 0)
116-
utf8::dump(std::back_inserter(*this), cp);
117-
}
118-
explicit String(Codepoint cp, ColumnCount count)
119-
{
120-
int cp_count = (int)(count / std::max(codepoint_width(cp), 1_col));
121-
reserve(utf8::codepoint_size(cp) * cp_count);
122-
while (cp_count-- > 0)
123-
utf8::dump(std::back_inserter(*this), cp);
124-
}
125112
String(const char* begin, const char* end) : m_data(begin, end-begin) {}
126-
113+
explicit String(Codepoint cp, CharCount count = 1);
114+
explicit String(Codepoint cp, ColumnCount count);
127115
explicit String(StringView str);
128116

129117
struct NoCopy{};

0 commit comments

Comments
 (0)