mirror of https://github.com/adamdruppe/arsd.git
killing allocation
This commit is contained in:
parent
d614f48642
commit
4f672591d8
48
mangle.d
48
mangle.d
|
@ -28,6 +28,32 @@ static immutable string[23] primitives = [
|
||||||
"dchar", // w
|
"dchar", // w
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// FIXME: using this will allocate at *runtime*! Unbelievable.
|
||||||
|
// it does that even if everything is enum
|
||||||
|
auto dTokensPain() {
|
||||||
|
string[] p = cast(string[]) primitives[];
|
||||||
|
string[] ret;
|
||||||
|
foreach(i; (sort!"a.length > b.length"(
|
||||||
|
p~
|
||||||
|
[
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
".",
|
||||||
|
",",
|
||||||
|
"!",
|
||||||
|
"[",
|
||||||
|
"]",
|
||||||
|
"*",
|
||||||
|
"const",
|
||||||
|
"immutable",
|
||||||
|
"shared",
|
||||||
|
"extern",
|
||||||
|
]))) { ret ~= i; }
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static immutable string[] dTokens = dTokensPain();
|
||||||
|
|
||||||
|
|
||||||
char manglePrimitive(in char[] t) {
|
char manglePrimitive(in char[] t) {
|
||||||
|
@ -60,26 +86,6 @@ struct StackArray(Type, size_t capacity) {
|
||||||
|
|
||||||
char[] mangle(const(char)[] decl, char[] buffer) {
|
char[] mangle(const(char)[] decl, char[] buffer) {
|
||||||
|
|
||||||
// FIXME: using this will allocate at *runtime*! Unbelievable.
|
|
||||||
// it does that even if everything is enum
|
|
||||||
auto dTokens = (sort!"a.length > b.length"(
|
|
||||||
primitives ~
|
|
||||||
[
|
|
||||||
"(",
|
|
||||||
")",
|
|
||||||
".",
|
|
||||||
",",
|
|
||||||
"!",
|
|
||||||
"[",
|
|
||||||
"]",
|
|
||||||
"*",
|
|
||||||
"const",
|
|
||||||
"immutable",
|
|
||||||
"shared",
|
|
||||||
"extern",
|
|
||||||
]));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
StackArray!(const(char)[], 128) tokensBuffer;
|
StackArray!(const(char)[], 128) tokensBuffer;
|
||||||
main: while(decl.length) {
|
main: while(decl.length) {
|
||||||
|
@ -286,6 +292,7 @@ version(unittest) {
|
||||||
S foo3(S, S, string, long, int, S, int[], char[][]);
|
S foo3(S, S, string, long, int, S, int[], char[][]);
|
||||||
long testcomplex(int, const(const(char)[]*)[], long);
|
long testcomplex(int, const(const(char)[]*)[], long);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest {
|
unittest {
|
||||||
import core.demangle;
|
import core.demangle;
|
||||||
char[512] buffer;
|
char[512] buffer;
|
||||||
|
@ -312,4 +319,5 @@ void main(string[] args) {
|
||||||
writeln(mangle(args[1], buffer));
|
writeln(mangle(args[1], buffer));
|
||||||
else
|
else
|
||||||
writeln(mangle("int test30.foo(int, immutable(char)[])", buffer));
|
writeln(mangle("int test30.foo(int, immutable(char)[])", buffer));
|
||||||
|
//mangle("int test30.foo(int, immutable(char)[])", buffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue