Skip to content

Commit 4047335

Browse files
WalterBrightthewilsonator
authored andcommitted
remove unnecessary overloads of setString()
1 parent b725592 commit 4047335

3 files changed

Lines changed: 23 additions & 43 deletions

File tree

compiler/src/dmd/frontend.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8920,9 +8920,6 @@ struct Token final
89208920
};
89218921
Identifier* ident;
89228922
};
8923-
void setString(const char* ptr, size_t length);
8924-
void setString(const OutBuffer& buf);
8925-
void setString();
89268923
const char* toChars() const;
89278924
static const char* toChars(TOK value);
89288925
Token() :

compiler/src/dmd/lexer.d

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ class Lexer
16351635
case 0:
16361636
case 0x1A:
16371637
error("unterminated string constant starting at %s", start.toChars());
1638-
result.setString();
1638+
result.setString(null);
16391639
// rewind `p` so it points to the EOF character
16401640
p--;
16411641
return;
@@ -1645,7 +1645,7 @@ class Lexer
16451645
if (supportInterpolation)
16461646
result.appendInterpolatedPart(stringbuffer);
16471647
else
1648-
result.setString(stringbuffer);
1648+
result.setString(stringbuffer[]);
16491649

16501650
stringPostfix(result);
16511651
return;
@@ -1698,7 +1698,7 @@ class Lexer
16981698
case 0:
16991699
case 0x1A:
17001700
error("unterminated string constant starting at %s", start.toChars());
1701-
t.setString();
1701+
t.setString(null);
17021702
// decrement `p`, because it needs to point to the next token (the 0 or 0x1A character is the TOK.endOfFile token).
17031703
p--;
17041704
return TOK.hexadecimalString;
@@ -1708,7 +1708,7 @@ class Lexer
17081708
error("odd number (%d) of hex characters in hex string", n);
17091709
stringbuffer.writeByte(cast(char)v);
17101710
}
1711-
t.setString(stringbuffer);
1711+
t.setString(stringbuffer[]);
17121712
stringPostfix(t);
17131713
return TOK.hexadecimalString;
17141714
default:
@@ -1801,7 +1801,7 @@ class Lexer
18011801
case 0:
18021802
case 0x1A:
18031803
error("unterminated delimited string constant starting at %s", start.toChars());
1804-
result.setString();
1804+
result.setString(null);
18051805
// decrement `p`, because it needs to point to the next token (the 0 or 0x1A character is the TOK.endOfFile token).
18061806
p--;
18071807
return;
@@ -1907,7 +1907,7 @@ class Lexer
19071907
error("delimited string must end in `\"`");
19081908
else
19091909
error(token.loc, "delimited string must end in `%c\"`", delimright);
1910-
result.setString(stringbuffersecondary);
1910+
result.setString(stringbuffersecondary[]);
19111911
stringPostfix(result);
19121912
}
19131913

@@ -1954,7 +1954,7 @@ class Lexer
19541954
if (supportInterpolation)
19551955
result.appendInterpolatedPart(pstart, p - 1 - pstart);
19561956
else
1957-
result.setString(pstart, p - 1 - pstart);
1957+
result.setString(pstart[0 .. p - 1 - pstart]);
19581958

19591959
stringPostfix(result);
19601960
return;
@@ -1976,7 +1976,7 @@ class Lexer
19761976
continue;
19771977
case TOK.endOfFile:
19781978
error("unterminated token string constant starting at %s", start.toChars());
1979-
result.setString();
1979+
result.setString(null);
19801980
return;
19811981
default:
19821982
continue;
@@ -2121,7 +2121,7 @@ class Lexer
21212121
if (supportInterpolation)
21222122
t.appendInterpolatedPart(stringbuffer);
21232123
else
2124-
t.setString(stringbuffer);
2124+
t.setString(stringbuffer[]);
21252125
if (!Ccompile)
21262126
stringPostfix(t);
21272127
return;
@@ -2131,7 +2131,7 @@ class Lexer
21312131
p--;
21322132
Lunterminated:
21332133
error("unterminated string constant starting at %s", start.toChars());
2134-
t.setString();
2134+
t.setString(null);
21352135
return;
21362136
default:
21372137
if (c & 0x80)

compiler/src/dmd/tokens.d

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -949,40 +949,23 @@ nothrow:
949949
}
950950

951951
/****
952-
* Set to contents of ptr[0..length]
952+
* Set to contents of str
953953
* Params:
954-
* ptr = pointer to string
955-
* length = length of string
954+
* str = string
956955
*/
957-
void setString(const(char)* ptr, size_t length)
956+
extern (D) void setString(const(char)[] str)
958957
{
959958
value = TOK.string_;
960-
auto s = cast(char*)mem.xmalloc_noscan(length + 1);
961-
memcpy(s, ptr, length);
962-
s[length] = 0;
963-
ustring = s;
964-
len = cast(uint)length;
965-
postfix = 0;
966-
}
967-
968-
/****
969-
* Set to contents of buf
970-
* Params:
971-
* buf = string (not zero terminated)
972-
*/
973-
void setString(const ref OutBuffer buf)
974-
{
975-
setString(cast(const(char)*)buf[].ptr, buf.length);
976-
}
977-
978-
/****
979-
* Set to empty string
980-
*/
981-
void setString()
982-
{
983-
value = TOK.string_;
984-
ustring = "";
985-
len = 0;
959+
len = cast(uint)str.length;
960+
if (len)
961+
{
962+
auto s = cast(char*)mem.xmalloc_noscan(len + 1);
963+
memcpy(s, str.ptr, len);
964+
s[len] = 0;
965+
ustring = s;
966+
}
967+
else
968+
ustring = "";
986969
postfix = 0;
987970
}
988971

0 commit comments

Comments
 (0)