Skip to content

Commit

Permalink
avoid use of D std for vector copies
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Sep 17, 2024
1 parent b018a8d commit 7545aec
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions source/numem/mem/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ private:
}
}

pragma(inline, true)
void memcpy(T* dst, T* src, size_t length) {
memcpy(dst, src, T.sizeof*length);
}

public:

/// Gets the type of character stored in the string.
Expand Down Expand Up @@ -133,7 +138,7 @@ public:
this(ref vector!T rhs) {
if (rhs.memory) {
this.resize_(rhs.size_);
this.memory[0..size_] = rhs.memory[0..rhs.size_];
this.memcpy(this.memory, rhs.memory, rhs.size_);
}
}

Expand All @@ -143,8 +148,11 @@ public:
@trusted
this(ref return scope inout(vector!T) rhs) inout {
if (rhs.memory) {
(cast(vector!T)this).resize_(rhs.size_);
(cast(vector!T)this).memory[0..size_] = (cast(vector!T)rhs).memory[0..rhs.size_];
auto self = (cast(vector!T)this);
auto other = (cast(vector!T)rhs);

self.resize_(rhs.size_);
other.memcpy(self.memory, other.memory, other.size_);
}
}
}
Expand Down

0 comments on commit 7545aec

Please sign in to comment.