diff --git a/source/nbuff/buffer.d b/source/nbuff/buffer.d index a26579e..e1ad3ce 100644 --- a/source/nbuff/buffer.d +++ b/source/nbuff/buffer.d @@ -828,6 +828,15 @@ struct Nbuff _pages._next = new_pages; } + this(string s) @nogc @safe + { + append(s); + } + this(immutable(ubyte)[] s) @nogc @safe + { + auto c = NbuffChunk(s); + append(c); + } /// /// copy references to RC-data /// @@ -1099,8 +1108,14 @@ struct Nbuff _endChunkIndex -= ChunksPerPage; } } - void pop(int n=1) @safe @nogc + void pop(long n=1) @safe @nogc { + assert(n <= _length); + if (n == _length) + { + clear(); + return; + } auto toPop = n; while(toPop > 0) { @@ -1836,6 +1851,15 @@ unittest auto n = NbuffChunk("abc"); } +@("Nbuff11") +unittest +{ + // init from string + auto b = Nbuff("abc"); + assert(b.length == 3); + assert(b.data.data == NbuffChunk("abc")); +} + version(Posix) { @("iovec") diff --git a/tests/bench.d b/tests/bench.d index 2833698..f16f89f 100644 --- a/tests/bench.d +++ b/tests/bench.d @@ -6,7 +6,7 @@ buildRequirements "allowWarnings" dependency "automem" version="*" dependency "ikod-containers" version="0.0.5" - dependency "nbuff" version="0.0.6" + dependency "nbuff" version="0.1.1" +/ import std.datetime.stopwatch; @@ -31,14 +31,7 @@ void main() chunk = Nbuff.get(2*s); b.append(chunk, s); } - void f1() - { - Buffer b; - auto s = uniform(16, 16*1024, rnd); - b.append(new ubyte[](s)); - b.append(new ubyte[](2*s)); - } - auto r = benchmark!(f0,f1)(1000000); + auto r = benchmark!(f0)(1_000_000); writefln("append, no data copy:\n%(%s\n%)", r); auto long_string = "A".repeat().take(2*16*1024).join(); @@ -54,19 +47,7 @@ void main() b.append(chunk, s); } } - void f3() - { - Buffer b; - auto limit = uniform(8, 32, rnd); - for(int i=0;i