Skip to content

Commit

Permalink
Remove custom newSeqUninit if available in stdlib (#592)
Browse files Browse the repository at this point in the history
* rename `newSeqUninit` in order to avoid conflicts with upstream

* use system `newSeqUninit` where applicable

In these cases we are only dealing with mem copyable POD types, so
it's fine to use the stdlib version.

* use regular `newSeq` in `toRawSeq`

The proc is deprecated anyway and the minor performance penalty should
be irrelevant.

* use system `newSeqUninit` if available

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
  • Loading branch information
Vindaar and ringabout authored Sep 28, 2023
1 parent 875ee6b commit bb6a90b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/arraymancer/private/sequninit.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# from Nim https://github.com/nim-lang/Nim/pull/22739 on the stdlib provides a
# `newSeqUninit` for types supporting `supportsCopyMem`
when not declared(newSeqUninit):
# https://github.com/nim-lang/Nim/pull/22586#issuecomment-1698160304

func newSeqUninit*[T](len: Natural): seq[T] {.inline.} =
## Creates an uninitialzed seq.
## Contrary to newSequnitialized in system.nim this works for any subtype T
Expand Down
2 changes: 1 addition & 1 deletion src/arraymancer/tensor/exporting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ proc toRawSeq*[T](t:Tensor[T]): seq[T] {.noSideEffect, deprecated: "This proc ca
# Due to forward declaration this proc must be declared
# after "cpu" proc are declared in init_cuda
when t is Tensor:
result = newSeqUninit[T](t.size)
result = newSeq[T](t.size)
for i in 0 ..< t.size:
when T is KnownSupportsCopyMem:
result[i] = t.unsafe_raw_offset()[i]
Expand Down

0 comments on commit bb6a90b

Please sign in to comment.