diff --git a/cdc.d b/cdc.d index 47bb12f..960a3a4 100755 --- a/cdc.d +++ b/cdc.d @@ -226,7 +226,7 @@ void main(string[] args) case "all": build("debug", "release", "unittest"); break; default: writeln("unknown build target: ", target); - writeln("available targets: 'debug', 'release', 'all'"); + writeln("available targets: 'debug', 'release', 'profile', 'all'"); } } diff --git a/dyaml/constructor.d b/dyaml/constructor.d index 55c2ed2..5ff3055 100644 --- a/dyaml/constructor.d +++ b/dyaml/constructor.d @@ -669,9 +669,9 @@ unittest Node[] pairs; foreach(long i; 0 .. length) { - auto pair = (i % 2) ? Pair(Node.rawNode(Node.Value(to!string(i))), Node.rawNode(Node.Value(i))) - : Pair(Node.rawNode(Node.Value(i)), Node.rawNode(Node.Value(to!string(i)))); - pairs ~= Node.rawNode(Node.Value([pair])); + auto pair = (i % 2) ? Pair(to!string(i), i) + : Pair(i, to!string(i)); + pairs ~= Node([pair]); } return pairs; } @@ -681,8 +681,8 @@ unittest Node[] pairs; foreach(long i; 0 .. length) { - auto pair = Pair(Node.rawNode(Node.Value(to!string(i))), Node.rawNode(Node.Value(i))); - pairs ~= Node.rawNode(Node.Value([pair])); + auto pair = Pair(to!string(i), i); + pairs ~= Node([pair]); } return pairs; } @@ -736,7 +736,7 @@ unittest Node.Pair[] pairs; foreach(long i; 0 .. length) { - pairs ~= Node.Pair(Node.rawNode(Node.Value(to!string(i))), Node.rawNode(Node.Value(YAMLNull()))); + pairs ~= Node.Pair(to!string(i), YAMLNull()); } return pairs; diff --git a/dyaml/node.d b/dyaml/node.d index 0449949..dd90442 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -632,7 +632,7 @@ struct Node * non-integral index is used with a sequence or the node is * not a collection. */ - Node opIndex(T)(T index) + ref Node opIndex(T)(T index) { if(isSequence) { diff --git a/dyaml/reader.d b/dyaml/reader.d index 63e6097..6b330f6 100644 --- a/dyaml/reader.d +++ b/dyaml/reader.d @@ -126,7 +126,8 @@ final class Reader } available_ = stream_.available; - bufferReserve(256); + auto ptr = cast(dchar*)core.stdc.stdlib.malloc(dchar.sizeof * 256); + bufferAllocated_ = ptr[0 .. 256]; } ///Destroy the Reader. diff --git a/dyaml/serializer.d b/dyaml/serializer.d index 451b5fb..600a853 100644 --- a/dyaml/serializer.d +++ b/dyaml/serializer.d @@ -146,20 +146,14 @@ struct Serializer } anchors_[node] = Anchor(null); - if(node.isSequence) + if(node.isSequence) foreach(ref Node item; node) { - foreach(ref Node item; node) - { - anchorNode(item); - } + anchorNode(item); } - else if(node.isMapping) + else if(node.isMapping) foreach(ref Node key, ref Node value; node) { - foreach(ref Node key, ref Node value; node) - { - anchorNode(key); - anchorNode(value); - } + anchorNode(key); + anchorNode(value); } } @@ -205,7 +199,7 @@ struct Serializer } if(node.isSequence) { - auto defaultTag = resolver_.defaultSequenceTag; + const defaultTag = resolver_.defaultSequenceTag; bool implicit = node.tag_ == defaultTag; emitter_.emit(sequenceStartEvent(Mark(), Mark(), aliased, node.tag_, implicit, CollectionStyle.Invalid)); diff --git a/dyaml/sharedobject.d b/dyaml/sharedobject.d index ff2bf8e..8da2723 100644 --- a/dyaml/sharedobject.d +++ b/dyaml/sharedobject.d @@ -33,9 +33,7 @@ template SharedObject(T, MixedIn) * * When this reaches zero, objects_ are cleared. This is not * the number of shared objects, but rather of objects using this kind - * of shared object. This is used e.g. with Anchor, but not with Tag - * - tags can be stored by the user in Nodes so there is no way to know - * when there are no Tags anymore. + * of shared object. */ int referenceCount_ = 0; @@ -124,7 +122,7 @@ template SharedObject(T, MixedIn) } ///Is this object null (invalid)? - bool isNull() const {return index_ == uint.max;} + @property bool isNull() const {return index_ == uint.max;} private: ///Add a new object, checking if identical object already exists. diff --git a/dyaml/tag.d b/dyaml/tag.d index a21fc42..c41fd0a 100644 --- a/dyaml/tag.d +++ b/dyaml/tag.d @@ -7,24 +7,63 @@ ///YAML tag. module dyaml.tag; -import dyaml.sharedobject; + +import core.stdc.string; ///YAML tag (data type) struct. Encapsulates a tag to save memory and speed-up comparison. struct Tag { - public: - mixin SharedObject!(string, Tag); + private: + ///Zero terminated tag string. + immutable(char)* tag_ = null; + public: ///Construct a tag from a string representation. this(string tag) { if(tag is null || tag == "") { - index_ = uint.max; + tag_ = null; return; } - add(tag); + tag_ = (tag ~ '\0').ptr; } + + ///Get the tag string. + @property string get() const + in{assert(!isNull());} + body + { + return cast(string)tag_[0 .. strlen(tag_)]; + } + + ///Test for equality with another tag. + bool opEquals(const ref Tag tag) const + { + return isNull ? tag.isNull : + tag.isNull ? false : (0 == strcmp(tag_, tag.tag_)); + } + + ///Compute a hash. + hash_t toHash() const + in{assert(!isNull);} + body + { + static type = typeid(string); + auto str = get(); + return type.getHash(&str); + } + + ///Compare with another tag. + int opCmp(const ref Tag tag) const + in{assert(!isNull && !tag.isNull);} + body + { + return strcmp(tag_, tag.tag_); + } + + ///Is this tag null (invalid)? + @property bool isNull() const {return tag_ is null;} }