Skip to content

Commit

Permalink
Improve the build times of dyaml.node
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkimax committed Mar 2, 2023
1 parent 2c915b3 commit fcce8db
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions source/dyaml/node.d
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,28 @@ struct Node
return this.value_.tryMatch!(
(inout bool v) @safe => v.to!TType,
(inout long v) @safe => v.to!TType,
(inout Node[] v) @trusted => v.to!TType,
(inout Node[] v) @trusted
{
static if (is(TType == string))
{
auto sink = appender!string();
sink ~= "[";

foreach(i, ref node; v)
{
if (i > 0)
sink ~= ", ";
node.toString(sink);
}

sink ~= "]";
return sink.data;
}
else
{
return v.to!TType;
}
},
(inout ubyte[] v) @safe => v.to!TType,
(inout string v) @safe => v.to!TType,
(inout Node.Pair[] v) @trusted => v.to!TType,
Expand Down Expand Up @@ -2510,11 +2531,27 @@ struct Node
this.value_.match!(
(const bool v) => formattedWrite(sink, v ? "true" : "false"),
(const long v) => formattedWrite(sink, "%s", v),
(const Node[] v) => formattedWrite(sink, "[%(%s, %)]", v),
(const Node[] v)
{
sink ~= "[";

foreach(i, ref node; v)
{
if (i > 0)
sink ~= ", ";
node.toString(sink);
}

sink ~= "]";
return 0;
},
(const ubyte[] v) => formattedWrite(sink, "%s", v),
(const string v) => formattedWrite(sink, `"%s"`, v),
(const Node.Pair[] v) => formattedWrite(sink, "{%(%s, %)}", v),
(const SysTime v) => formattedWrite(sink, "%s", v),
(const SysTime v) {
v.toString(sink);
return 0;
},
(const YAMLNull v) => formattedWrite(sink, "%s", v),
(const YAMLMerge v) => formattedWrite(sink, "%s", v),
(const real v) => formattedWrite(sink, "%s", v),
Expand Down

0 comments on commit fcce8db

Please sign in to comment.