From 9814e5ad8ef246273cad80f86c95c3bce047509a Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 14 Apr 2019 07:41:26 +0200 Subject: [PATCH] Pass allocator in all HashTable/Set constructors --- .travis.yml | 4 ++-- README.md | 2 +- appveyor.yml | 4 ++-- source/tanya/container/hashtable.d | 9 ++++---- source/tanya/container/list.d | 36 ++++++++++++++---------------- source/tanya/container/set.d | 14 ++++++++---- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8478837..3912578 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,12 @@ os: language: d d: -- dmd-2.085.0 +- dmd-2.085.1 - dmd-2.081.2 env: global: - - LATEST=2.085.0 + - LATEST=2.085.1 matrix: - ARCH=x86_64 diff --git a/README.md b/README.md index 5232a57..c3004ef 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ parameter is used) | DMD | GCC | |:-----------------:|:---------------:| -| 2.081.2 — 2.085.0 | gdc-8 (2.081.2) | +| 2.081.2 — 2.085.1 | gdc-8 (2.081.2) | | | gdc-7 (2.081.2) | ### Release management diff --git a/appveyor.yml b/appveyor.yml index ed63de4..1a67031 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,10 +4,10 @@ os: Visual Studio 2015 environment: matrix: - DC: dmd - DVersion: 2.085.0 + DVersion: 2.085.1 arch: x64 - DC: dmd - DVersion: 2.085.0 + DVersion: 2.085.1 arch: x86 - DC: dmd DVersion: 2.081.2 diff --git a/source/tanya/container/hashtable.d b/source/tanya/container/hashtable.d index f458ca5..2ae18db 100644 --- a/source/tanya/container/hashtable.d +++ b/source/tanya/container/hashtable.d @@ -416,8 +416,8 @@ if (isHashFunction!(hasher, Key)) * * Precondition: $(D_INLINECODE allocator !is null). */ - this(R)(R range, shared Allocator allocator = defaultAllocator) - if (isForwardRange!R && is(ElementType!R == KeyValue)) + this(R)(scope R range, shared Allocator allocator = defaultAllocator) + if (isForwardRange!R && is(ElementType!R == KeyValue) && !isInfinite!R) in (allocator !is null) { this(allocator); @@ -450,6 +450,7 @@ if (isHashFunction!(hasher, Key)) shared Allocator allocator = defaultAllocator) in (allocator !is null) { + this(allocator); insert(array[]); } @@ -714,8 +715,8 @@ if (isHashFunction!(hasher, Key)) * * Returns: The number of the inserted elements with a unique key. */ - size_t insert(R)(R range) - if (isForwardRange!R && is(ElementType!R == KeyValue)) + size_t insert(R)(scope R range) + if (isForwardRange!R && is(ElementType!R == KeyValue) && !isInfinite!R) { size_t count; foreach (e; range) diff --git a/source/tanya/container/list.d b/source/tanya/container/list.d index 279ebc4..caa7bd0 100644 --- a/source/tanya/container/list.d +++ b/source/tanya/container/list.d @@ -39,7 +39,7 @@ struct SRange(L) invariant (this.head !is null); - private this(ref EntryPointer head) @trusted + private this(return ref EntryPointer head) @trusted { this.head = &head; } @@ -127,7 +127,7 @@ struct SList(T) * init = Values to initialize the list with. * allocator = Allocator. */ - this(R)(R init, shared Allocator allocator = defaultAllocator) + this(R)(scope R init, shared Allocator allocator = defaultAllocator) if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -372,7 +372,7 @@ struct SList(T) } /// ditto - size_t insertFront(R)(R el) @trusted + size_t insertFront(R)(scope R el) @trusted if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -473,7 +473,7 @@ struct SList(T) } /// ditto - size_t insertBefore(R)(Range r, R el) + size_t insertBefore(R)(Range r, scope R el) if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -798,7 +798,7 @@ struct SList(T) * * Returns: $(D_KEYWORD this). */ - ref typeof(this) opAssign(R)(R that) @trusted + ref typeof(this) opAssign(R)(scope R that) @trusted if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -893,7 +893,8 @@ struct DRange(L) invariant (this.head !is null); invariant (this.tail !is null); - private this(ref EntryPointer head, ref EntryPointer tail) @trusted + private this(return ref EntryPointer head, return ref EntryPointer tail) + @trusted { this.head = &head; this.tail = &tail; @@ -1010,7 +1011,7 @@ struct DList(T) * init = Values to initialize the list with. * allocator = Allocator. */ - this(R)(R init, shared Allocator allocator = defaultAllocator) + this(R)(scope R init, shared Allocator allocator = defaultAllocator) if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -1261,13 +1262,10 @@ struct DList(T) // Creates a lsit of linked entries from a range. // Returns count of the elements in the list. - private size_t makeList(R)(ref R el, out Entry* head, out Entry* tail) @trusted - out (retLength) - { - assert((retLength == 0 && head is null && tail is null) - || (retLength > 0 && head !is null && tail !is null)); - } - do + private size_t makeList(R)(scope ref R el, out Entry* head, out Entry* tail) + @trusted + out (retLength; (retLength == 0 && head is null && tail is null) + || (retLength > 0 && head !is null && tail !is null)) { size_t retLength; @@ -1335,7 +1333,7 @@ struct DList(T) } /// ditto - size_t insertFront(R)(R el) + size_t insertFront(R)(scope R el) if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -1454,7 +1452,7 @@ struct DList(T) } /// ditto - size_t insertBack(R)(R el) @trusted + size_t insertBack(R)(scope R el) @trusted if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -1581,7 +1579,7 @@ struct DList(T) } /// ditto - size_t insertBefore(R)(Range r, R el) + size_t insertBefore(R)(Range r, scope R el) if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -1686,7 +1684,7 @@ struct DList(T) } /// ditto - size_t insertAfter(R)(Range r, R el) + size_t insertAfter(R)(Range r, scope R el) if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) @@ -2067,7 +2065,7 @@ struct DList(T) * * Returns: $(D_KEYWORD this). */ - ref typeof(this) opAssign(R)(R that) @trusted + ref typeof(this) opAssign(R)(scope R that) @trusted if (!isInfinite!R && isInputRange!R && isImplicitlyConvertible!(ElementType!R, T)) diff --git a/source/tanya/container/set.d b/source/tanya/container/set.d index 7bfa6aa..ae0a0fd 100644 --- a/source/tanya/container/set.d +++ b/source/tanya/container/set.d @@ -218,10 +218,13 @@ if (isHashFunction!(hasher, T)) * * Precondition: $(D_INLINECODE allocator !is null). */ - this(R)(R range, shared Allocator allocator = defaultAllocator) - if (isForwardRange!R && isImplicitlyConvertible!(ElementType!R, T)) + this(R)(scope R range, shared Allocator allocator = defaultAllocator) + if (isForwardRange!R + && isImplicitlyConvertible!(ElementType!R, T) + && !isInfinite!R) in (allocator !is null) { + this(allocator); insert(range); } @@ -248,6 +251,7 @@ if (isHashFunction!(hasher, T)) this(size_t n)(T[n] array, shared Allocator allocator = defaultAllocator) in (allocator !is null) { + this(allocator); insert(array[]); } @@ -456,8 +460,10 @@ if (isHashFunction!(hasher, T)) * * Returns: The number of new elements inserted. */ - size_t insert(R)(R range) - if (isForwardRange!R && isImplicitlyConvertible!(ElementType!R, T)) + size_t insert(R)(scope R range) + if (isForwardRange!R + && isImplicitlyConvertible!(ElementType!R, T) + && !isInfinite!R) { size_t count; foreach (e; range)