Skip to content

Commit

Permalink
Bugfixes and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
lodo1995 committed Jul 29, 2016
1 parent 0ce169a commit d4fc3ed
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 70 deletions.
4 changes: 3 additions & 1 deletion source/std/experimental/appender.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ struct Appender(T, Alloc)
delta = max(arr.length, requiredGrowth);
else
delta = max(arr.length/2, requiredGrowth);
assert(allocator.expandArray(arr, delta), "Could not grow appender array");

auto done = allocator.expandArray(arr, delta);
assert(done, "Could not grow appender array");
}

/**
Expand Down
10 changes: 1 addition & 9 deletions source/std/experimental/xml/cursor.d
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,7 @@ struct CopyingCursor(CursorType, Alloc = shared(GCAllocator), Flag!"intern" inte
{
alias StringType = CursorType.StringType;

private Alloc* allocator;
this(ref Alloc alloc)
{
allocator = &alloc;
}
this(Alloc* alloc)
{
allocator = alloc;
}
mixin UsesAllocator!Alloc;

CursorType cursor;
alias cursor this;
Expand Down
6 changes: 2 additions & 4 deletions source/std/experimental/xml/domimpl.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@

module std.experimental.xml.domimpl;

import std.experimental.xml.interfaces;
import dom = std.experimental.xml.dom;
import std.typecons: rebindable;
import std.experimental.allocator;
import std.experimental.allocator.gc_allocator;

class DOMImplementation(DOMString, Alloc = shared(GCAllocator)): dom.DOMImplementation!DOMString
{
static if (is(typeof(Alloc.instance)))
private Alloc* allocator = &(Alloc.instance);
else
private Alloc* allocator;
mixin UsesAllocator!(Alloc, true);

override
{
Expand Down
37 changes: 37 additions & 0 deletions source/std/experimental/xml/interfaces.d
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,41 @@ template isSaveableCursor(CursorType)
CursorType cursor1;
CursorType cursor2 = cursor1.save();
}));
}

// PRIVATE STUFF

package mixin template UsesAllocator(Alloc, bool genDefaultCtor = false)
{
static if (is(Alloc == class))
private alias TrueAlloc = Alloc;
else
private alias TrueAlloc = Alloc*;

static if (is(typeof(Alloc.instance) == Alloc))
{
static if (is(Alloc == class))
private TrueAlloc allocator = Alloc.instance;
else
private TrueAlloc allocator = &(Alloc.instance);

static if (genDefaultCtor)
this() {}
}
else
{
private TrueAlloc allocator;
@disable this();
}

this(TrueAlloc allocator)
{
this.allocator = allocator;
}

static if (!is(Alloc == class))
this(ref Alloc allocator)
{
this.allocator = &allocator;
}
}
70 changes: 15 additions & 55 deletions source/std/experimental/xml/lexers.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ import std.typecons: Flag, Yes;
+
+ Parameters:
+ T = a sliceable type used as input for this lexer
+ Alloc = a dummy allocator parameter, never used; kept for uniformity with
+ the other lexers
+/
struct SliceLexer(T)
struct SliceLexer(T, Alloc = shared(GCAllocator))
{
private T input;
private size_t pos;
Expand All @@ -65,6 +67,8 @@ struct SliceLexer(T)
/// ditto
alias InputType = T;

mixin UsesAllocator!Alloc;

/// ditto
void setSource(T input) @nogc
{
Expand All @@ -74,11 +78,10 @@ struct SliceLexer(T)

static if(isForwardRange!T)
{
auto save() const @nogc
auto save() @nogc
{
SliceLexer result;
result.input = input;
result.pos = pos;
SliceLexer result = this;
result.input = input.save;
return result;
}
}
Expand Down Expand Up @@ -178,24 +181,10 @@ struct RangeLexer(T, Alloc = shared(GCAllocator), Flag!"reuseBuffer" reuseBuffer
/// ditto
alias InputType = T;

static if (is(typeof(Alloc.instance)))
private Alloc* allocator = &(Alloc.instance);
else
private Alloc* allocator;
mixin UsesAllocator!Alloc;

private Appender!(CharacterType, Alloc) app;

/// Constructs an instance of this lexer with the given allocator
this(Alloc* alloc)
{
allocator = alloc;
}
/// ditto
this(ref Alloc alloc)
{
allocator = &alloc;
}

import std.string: representation;
static if (is(typeof(representation!CharacterType(""))))
{
Expand Down Expand Up @@ -332,34 +321,19 @@ struct ForwardLexer(T, Alloc = shared(GCAllocator), Flag!"reuseBuffer" reuseBuff
/// ditto
alias InputType = T;

static if (is(typeof(Alloc.instance)))
private Alloc* allocator = &(Alloc.instance);
else
private Alloc* allocator;

mixin UsesAllocator!Alloc;

private size_t count;
private Appender!(CharacterType, Alloc) app;

/// Constructs an instance of this lexer with the given allocator
this(Alloc* alloc)
{
allocator = alloc;
app = typeof(app)(allocator);
}
/// ditto
this(ref Alloc alloc)
{
allocator = &alloc;
app = typeof(app)(allocator);
}

import std.string: representation;
static if (is(typeof(representation!CharacterType(""))))
{
private typeof(representation!CharacterType("")) input;
private typeof(input) input_start;
void setSource(T input)
{
app = typeof(app)(allocator);
this.input = input.representation;
this.input_start = this.input;
}
Expand All @@ -370,6 +344,7 @@ struct ForwardLexer(T, Alloc = shared(GCAllocator), Flag!"reuseBuffer" reuseBuff
private T input_start;
void setSource(T input)
{
app = typeof(app)(allocator);
this.input = input;
this.input_start = input;
}
Expand Down Expand Up @@ -509,27 +484,11 @@ struct BufferedLexer(T, Alloc = shared(GCAllocator), Flag!"reuseBuffer" reuseBuf
private InputType buffers;
private size_t pos;
private size_t begin;

static if (is(typeof(Alloc.instance)))
private Alloc* allocator = &(Alloc.instance);
else
private Alloc* allocator;

private Appender!(CharacterType, Alloc) app;
private bool onEdge;

/// Constructs an instance of this lexer with the given allocator
this(Alloc* alloc)
{
allocator = alloc;
app = typeof(app)(allocator);
}
/// ditto
this(ref Alloc alloc)
{
allocator = &alloc;
app = typeof(app)(allocator);
}
mixin UsesAllocator!Alloc;

import std.string: representation, assumeUTF;
static if (is(typeof(representation!CharacterType(""))))
Expand Down Expand Up @@ -557,6 +516,7 @@ struct BufferedLexer(T, Alloc = shared(GCAllocator), Flag!"reuseBuffer" reuseBuf
+/
void setSource(T input)
{
app = typeof(app)(allocator);
this.buffers = input;
popBuffer;
}
Expand Down
1 change: 0 additions & 1 deletion source/std/experimental/xml/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ struct Parser(L, Flag!"preserveWhitespace" preserveWhitespace = No.preserveWhite
// processing instruction
else if (lexer.testAndAdvance('?'))
{
size_t c;
do
lexer.advanceUntil('?', true);
while (!lexer.testAndAdvance('>'));
Expand Down

0 comments on commit d4fc3ed

Please sign in to comment.