Vector: Reuse available methods

This commit is contained in:
Eugen Wissner 2017-01-15 08:38:19 +01:00
parent 48205b2fc9
commit 4ea9c2b740
5 changed files with 18 additions and 34 deletions

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Copyright: Eugene Wissner 2016.
* Copyright: Eugene Wissner 2016-2017.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)

View File

@ -5,7 +5,7 @@
/*
* Internal package used by containers that rely on entries/nodes.
*
* Copyright: Eugene Wissner 2016.
* Copyright: Eugene Wissner 2016-2017.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Copyright: Eugene Wissner 2016.
* Copyright: Eugene Wissner 2016-2017.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Copyright: Eugene Wissner 2016.
* Copyright: Eugene Wissner 2016-2017.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)

View File

@ -402,18 +402,10 @@ struct Vector(T)
* len = Initial length of the vector.
* allocator = Allocator.
*/
this(size_t len, shared Allocator allocator = defaultAllocator) @trusted
this(size_t len, shared Allocator allocator = defaultAllocator)
{
this(allocator);
vector = cast(T*) allocator.allocate(len * T.sizeof);
if (len == 0)
{
return;
}
reserve(len);
initializeAll(vector[0 .. len]);
length_ = len;
length = len;
}
/**
@ -477,19 +469,10 @@ struct Vector(T)
/**
* Destroys this $(D_PSYMBOL Vector).
*/
~this() @trusted
~this()
{
static if (hasElaborateDestructor!T)
{
const T* end = vector + length_;
for (T* e = vector; e != end; ++e)
{
destroy(*e);
}
}
allocator.deallocate(cast(void[]) vector[0 .. capacity_]);
vector = null;
capacity_ = length_ = 0;
length = 0;
shrink(0);
}
/**
@ -695,7 +678,7 @@ struct Vector(T)
*/
@property bool empty() const
{
return length_ == 0;
return length == 0;
}
/**
@ -812,16 +795,17 @@ struct Vector(T)
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
{
immutable rLen = walkLength(el);
reserve(length_ + rLen);
T* pos = vector + length_;
static if (hasLength!R)
{
reserve(length_ + el.length);
}
size_t retLength;
foreach (e; el)
{
emplace(pos, e);
++length_, ++pos;
insertBack(e);
++retLength;
}
return rLen;
return retLength;
}
/// Ditto.