Skip to content

Commit 0a2a8dd

Browse files
authored
use put() instead of writestring() in hdrgen.d (dlang#21442)
1 parent 2fac6d6 commit 0a2a8dd

3 files changed

Lines changed: 393 additions & 378 deletions

File tree

compiler/src/dmd/common/outbuffer.d

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ struct OutBuffer
232232

233233
alias put = write; // transition to output range which uses put()
234234

235-
extern (C++) void write(const(void)* data, size_t nbytes) pure nothrow @system
235+
extern (C++) void write(scope const(void)* data, size_t nbytes) pure nothrow @system
236236
{
237237
put(data[0 .. nbytes]);
238238
}
@@ -246,6 +246,23 @@ struct OutBuffer
246246
offset += buf.length;
247247
}
248248

249+
void write(scope string buf) pure nothrow @trusted // so write("hello") chooses this overload
250+
{
251+
if (doindent && !notlinehead)
252+
indent();
253+
reserve(buf.length);
254+
memcpy(this.data.ptr + offset, buf.ptr, buf.length);
255+
offset += buf.length;
256+
}
257+
258+
extern (C++) void write(scope const(char)* s) pure nothrow @trusted
259+
{
260+
if (!s)
261+
return;
262+
import core.stdc.string : strlen;
263+
put(s[0 .. strlen(s)]);
264+
}
265+
249266
/**
250267
* Writes a 16 bit value, no reserve check.
251268
*/
@@ -286,10 +303,7 @@ struct OutBuffer
286303
/// Buffer will NOT be zero-terminated
287304
extern (C++) void writestring(const(char)* s) pure nothrow @system
288305
{
289-
if (!s)
290-
return;
291-
import core.stdc.string : strlen;
292-
put(s[0 .. strlen(s)]);
306+
put(s);
293307
}
294308

295309
/// ditto
@@ -307,7 +321,7 @@ struct OutBuffer
307321
/// Buffer will NOT be zero-terminated, followed by newline
308322
void writestringln(const(char)[] s) pure nothrow @safe
309323
{
310-
writestring(s);
324+
put(s);
311325
writenl();
312326
}
313327

compiler/src/dmd/frontend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ struct OutBuffer final
10421042
void setsize(size_t size);
10431043
void reset();
10441044
void write(const void* data, size_t nbytes);
1045+
void write(const char* s);
10451046
void writestring(const char* s);
10461047
void prependstring(const char* string);
10471048
void writenl();

0 commit comments

Comments
 (0)