[phobos] [D-Programming-Language/phobos] ceda4e: std.array.join refactor.

GitHub noreply at github.com
Sun Dec 30 15:24:36 PST 2012


  Branch: refs/heads/master
  Home:   https://github.com/D-Programming-Language/phobos
  Commit: ceda4e288070281039467b3318189f6360091347
      https://github.com/D-Programming-Language/phobos/commit/ceda4e288070281039467b3318189f6360091347
  Author: Peter Alexander <peter.alexander.au at gmail.com>
  Date:   2012-12-26 (Wed, 26 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  std.array.join refactor.

tl;dr: std.array.join was quite complicated: 6 implementation functions, and a few hundred lines of code. Now it is just 2 functions, ~120 lines of code smaller, and within 10% performance of original (faster in some cases).

The original had 6 implementations: 3 joins with a separator, 3 without. For each, those 3 consisted of:
* A general slow version (uses `std.algorithm.joiner` with `appender`).
* A version for a range of arrays where you know the length (pre-allocates the destination array then uses array ops).
* A version for a range of arrays where you don't know the length (uses `appender`).

There's no need for the second version because you can just use appender and `.reserve` the size upfront. Appender already uses array ops when available in its `put` function.

There's also no need for the first function because using `joiner` is slower than just looping through the sub-ranges, appending them. The third function doesn't even use the fact that its operating on a range of arrays, so it can easily be merged with the first and second.

The end result is just one function for join with a separator, and one for a join without. They both use `appender`, and have a static branch that will `.reserve` the required size when the information is available.


  Commit: b6c9ffed919f0f3b683377d46c306c9a81a3502e
      https://github.com/D-Programming-Language/phobos/commit/b6c9ffed919f0f3b683377d46c306c9a81a3502e
  Author: Peter Alexander <peter.alexander.au at gmail.com>
  Date:   2012-12-26 (Wed, 26 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  Fix for mismatched string types + added unittests.


  Commit: 221ea836faace6b3d1b70f85f9a7f2724675b46c
      https://github.com/D-Programming-Language/phobos/commit/221ea836faace6b3d1b70f85f9a7f2724675b46c
  Author: Peter Alexander <peter.alexander.au at gmail.com>
  Date:   2012-12-27 (Thu, 27 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  Convert sep to array for performance/generality.


  Commit: 83cf1854db684bd38360fe4fcb1f90b91f27c8b3
      https://github.com/D-Programming-Language/phobos/commit/83cf1854db684bd38360fe4fcb1f90b91f27c8b3
  Author: Peter Alexander <peter.alexander.au at gmail.com>
  Date:   2012-12-27 (Thu, 27 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  Fix for non-array separators for non-string RoR.


  Commit: d24519ee47698167cb00ef7a7840a60f38f0b231
      https://github.com/D-Programming-Language/phobos/commit/d24519ee47698167cb00ef7a7840a60f38f0b231
  Author: Peter Alexander <peter.alexander.au at gmail.com>
  Date:   2012-12-28 (Fri, 28 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  More improvements and optimisations to array.join


  Commit: 9d8c78d1804fd47c502c34dc8308a4823a2a1ba5
      https://github.com/D-Programming-Language/phobos/commit/9d8c78d1804fd47c502c34dc8308a4823a2a1ba5
  Author: Peter Alexander <peter.alexander.au at gmail.com>
  Date:   2012-12-30 (Sun, 30 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  Changed foreach to for to avoid copies + cleanup


  Commit: bdcf9195cb85283b9aad87d1272148c97f924b7e
      https://github.com/D-Programming-Language/phobos/commit/bdcf9195cb85283b9aad87d1272148c97f924b7e
  Author: Andrei Alexandrescu <andrei at erdani.com>
  Date:   2012-12-30 (Sun, 30 Dec 2012)

  Changed paths:
    M std/array.d

  Log Message:
  -----------
  Merge pull request #1036 from Poita/array-join-refactor

std.array.join refactor.


Compare: https://github.com/D-Programming-Language/phobos/compare/628fd6a05e62...bdcf9195cb85


More information about the phobos mailing list