Commit graph

286 commits

Author SHA1 Message Date
dkorpel
f7c93036b3 Fix return/inout usage in rbtree 2022-02-16 16:27:04 +00:00
wolframw
dc697c8dd8 Fix Issue 22105 - std.container.array.Array.length setter creates values of init-less types 2021-12-28 23:33:31 +00:00
dkorpel
ea76f45494 Use return scope instead of just return 2021-11-26 17:03:06 +01:00
Ömer Faruk IRMAK
61d3fe3293 Add explicit default ctor for DList.PayNode
Worksaround Issue 22510 (https://issues.dlang.org/show_bug.cgi?id=22510)
which prevented us from using structs with explicit copy ctors with DList.
2021-11-14 14:50:23 +03:00
Petar Kirov
dfaaf8fa53 Merge remote-tracking branch 'upstream/stable' into merge_stable 2021-11-09 10:30:28 +02:00
MoonlightSentinel
c0981769a0 Fix 22487 - Don't access payload for unititialized array data
Explicitly return `[]` when `store` wasn't intialized yet.
2021-11-08 05:40:08 +00:00
MoonlightSentinel
a22571f59a Fix 22488 - Add inout to allow Array.data for const/immutable Array's
Simply propagate the const'ness to the return slice.
2021-11-08 05:34:08 +00:00
DoctorNoobingstoneIPresume
6b05400fba std.container.Array: Payload.reserve re-used, object leak fixed.
This is another attempt to re-use the code in `Payload.reserve` --
similar to https://github.com/dlang/phobos/pull/8143 (commit 0b7bf8dc):
"std.container.Array: Simplify implementation of length (by calling reserve).".

Additionally, `Array`'s variadic constructor is now safer:

  If `emplace`-ing an element fails, successfully `emplace`-d elements are now destroyed.

  Example:

  ```
    auto a = Array!S (S(0), S(1), S(2), S(3));

    // If emplace-ing a[2] (as a copy of S(2)) fails:
    //   - pre-existing behaviour: a[1] and a[0] were not destroyed (bad);
    //   - new behaviour:          a[1] and a[0] are      destroyed (good).
  ```

  A corresponding `unittest` has been added (`S.s_nDestroyed == S.s_nConstructed`):
    When such a failure (`Exception`) is caught, there should be no leaked objects.

  Implementation:
    Previously:
      - the `Payload` `length` used to be increased only once,
        after having successfully `emplace`-d all elements,
        thus incorrectly tracking the number of `emplace`-d elements during the loop
        (but correctly tracking it after the loop -- iff the entire loop succeeded).
    Now:
      - the `Payload` `length` is incremented multiple times,
        at each step i.e. after having successfully `emplace`-d each element,
        thus correctly tracking the number of `emplace`-d elements during the loop.
    Note:
      When the constructor fails, the corresponding destructor is not run.
      But the destructors for successfully constructed sub-objects are run;
      in this case, the destructor for the `_data` sub-object is run --
      and it is this destructor which destroys the successfully emplaced elements
      (iff they have been correctly tracked).
2021-09-27 02:23:14 +03:00
dkorpel
53cd09c1fb mark RBNode.left and RBNode.right @trusted 2021-08-09 12:29:07 +02:00
Razvan Nitu
b48cca57e8
Merge pull request #8151 from DoctorNoobingstoneIPresume/210615_std_container_array_Payload_insertBack_01h
std.container.Array: insertBack: Extra checks (including addition overflow).
2021-07-28 18:30:26 +08:00
dandrei279
11bf097658
[DSSv3] Fix Issue #21100: Add data() function to std.container.array.Array (#8174)
[DSSv3] Fix Issue #21100: Add data() function to std.container.array.Array

Signed-off-by: Max Haughton <maxhaton@users.noreply.github.com>
Merged-on-behalf-of: Max Haughton <maxhaton@users.noreply.github.com>
2021-07-21 02:23:10 +00:00
Vladimir Panteleev
9baab6030a std.container.array: Hide unintentionally-public unittest
This is a unittest for a bug, not a public example.
2021-07-05 05:40:36 +00:00
DoctorNoobingstoneIPresume
7f9cc3fbbb std.container.Array: insertBack: Extra checks (including addition overflow). 2021-06-22 19:33:33 +03:00
DoctorNoobingstoneIPresume
0b7bf8dc1f std.container.Array: Simplify implementation of length (by calling reserve). 2021-06-14 05:05:39 +00:00
nordlow
4ba167b15b Annotate std/container/dlist.d to please dlang/dmd#12520 2021-05-18 01:58:16 +02:00
DoctorNoobingstoneIPresume
afeb00d580 container.array: RangeT: moveBack: Improve an assertion. 2021-05-04 08:13:40 +02:00
Razvan Nitu
6e11524c6f
Merge pull request #7189 from burner/assert_messages_container_package
adds assert messages to std.container.package
2021-04-21 20:46:12 +08:00
Razvan Nitu
89abc75f02
Merge pull request #7745 from kinke/emplace
Get rid of std.conv.emplace[Ref](), use core[.internal].lifetime
2021-01-25 15:36:04 +08:00
Luís Ferreira
e0bbaf3649 container: array: simplify some unittests by using Array!bool ctor instead
Since ae90bc7, we can simplify unittests by using Array!bool ctor instead of
manually do .insertBack(...). This improves example code readability.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
2021-01-23 07:26:39 +01:00
Razvan Nitu
d7fd00d792
Merge pull request #7752 from ljmf00/container-array-ctor-bool
container: array: add ctors for Array!bool
2021-01-22 15:30:10 +08:00
Luís Ferreira
ce558d26b1 container: array: add type checks for passed arguments in insertAfter()
insertAfter should receive a valid element or a Range of values according to
type T of the corresponding instance Array!T.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
2021-01-19 03:42:45 +01:00
Luís Ferreira
ae90bc7d9e
container: array: add ctors for Array!bool
Array!bool should have the same ctors as Array!T for other types.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
2021-01-18 23:14:26 +00:00
Luís Ferreira
30f71fd570
Fix issues 21555, 21556: container: array: add missing tests for Array!T .insertBack and .insertAfter
Signed-off-by: Luís Ferreira <contact@lsferreira.net>
2021-01-18 20:55:12 +00:00
Luís Ferreira
93ebaa7291
Fix issue 21555: std.container.array: insertBack is wrong and should be tested for Array!bool
insertBack() returns 0 inserted elements everytime due to a preformed
.popFront() on the range.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
2021-01-18 20:54:14 +00:00
Martin Kinkelin
1a459c5996 Get rid of std.conv.emplace[Ref](), use core[.internal].lifetime
The emplace() stuff was moved to druntime; for some reason, it's still
in Phobos.

I've diffed the two versions, and they are still almost identical (incl.
unittests); the druntime version appears to have seen some improvements
(e.g., forwarding r/lvalueness of the arguments) in the meantime.
2021-01-17 16:02:25 +01:00
Nathan Sashihara
fe1deb2f84 Fix a few places where opDollar could be an alias of length 2020-11-11 02:09:56 +01:00
Simon Naarmann
b0b64c3f41
RedBlackTree.empty: const, .front/.back: inout (#7644)
* RedBlackTree.empty(): Annotated const

RedBlackTree is a template, therefore all other qualifiers
for empty(), length(), and opBinaryRight!"in" will be inferred:
pure, nothrow, @safe, @nogc.

* RedBlackTree.front, .back: inout
2020-09-30 13:29:29 +08:00
Iain Buclaw
68e7cbdbc2 std.container: Fix warnings that memory may be used uninitialized
This is a warning that showed up when running the testsuite in GDC with
the -Wextra flag.  Said warning is by design and based on the assumption
that any function declared to take a const pointer or reference as an
argument reads the pointed-to-object.

In the case of GC.addRange(), the possibility is that a scan could
occur before the memory is initialized, and the GC sees false pointers
as a result of that.
2020-09-16 10:47:10 +02:00
Nathan Sashihara
453faadf5b Replace is(Unqual!T == Unqual!U) with is(immutable T == immutable U) for speed & memory usage 2020-08-03 15:07:32 +02:00
Steven Schveighoffer
b842a66f57 Move stableRemove alias to correct place 2020-07-11 08:58:22 +02:00
Geod24
62c72ca6ff Follow up review on PR 7441
Steven identified a couple mistakes in the massive round of linkification.
Fixing them here.
2020-04-15 02:15:04 +09:00
Geod24
04f3979317 Replace 'Issue XXX' with Bugzilla links
Make the links clickable, as was done in the DMD repository.
Also avoids any ambiguity w.r.t. where the issue is stored.
2020-04-13 16:28:09 +09:00
drug007
e4959d4777 Test for issue 20589 2020-02-26 20:05:34 +03:00
The Dlang Bot
3d322b7cc4
Merge pull request #7370 from burner/std.container.rbtree_assert_messages
adding assert messages to rbtree
merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>
2020-02-02 04:24:33 +01:00
The Dlang Bot
6a8350c688
Merge pull request #7369 from burner/std.container.binary_heap_assert_messages
adding assert messages to std.container.binary_heap
merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>
2020-02-02 04:23:10 +01:00
Robert Schadek
a0f381c514 adding assert messages to std.container.binary_heap 2020-01-27 14:10:32 +00:00
Robert Schadek
8456482ec1 adding assert messages to std.container.slist 2020-01-27 09:32:57 +00:00
Robert Schadek
09bede3b80 adding assert messages to rbtree 2020-01-27 09:23:07 +00:00
Alexandru Militaru
bb62aaca3d Replaced version (unittest) with version (StdUnittest) to avoid unnecessary overhead when compiling with -unittest 2020-01-19 14:05:17 +02:00
Robert Schadek
e70d86b75d Add assert messages for container.array (#7190) 2019-11-04 13:08:28 +02:00
Bernhard Seckinger
79ef683f5c Fix issue 19626 - RedBlackTree of an enum fails in unittest mode 2019-10-17 20:12:22 +02:00
Robert burner Schadek
6786e4228e Geod24 typo fixes 2019-09-21 15:12:25 +01:00
Robert Schadek
a670c53592 adds assert messages to std.container.dlist 2019-09-20 12:30:32 +08:00
Robert Schadek
0cd5c58793 adds assert messages to std.container.package 2019-09-20 12:04:42 +08:00
Nathan Sashihara
d35c93dac7 Avoid mulu in std.container.array.Array!T when T.sizeof == 1
LDC 1.15 and GDC with optimizations enabled recognize that mulu
with a second argument of 1 will never overflow and elide unnecessary
operations but DMD and LDC 1.14 do not.
2019-06-01 08:50:23 -04:00
Walter Bright
fc84e14d54 std.container.rbtree: compile with -dip1000 2019-03-20 12:15:19 -07:00
Walter Bright
fbfd844fd9 rbtree _add need only return a bool 2019-03-19 22:56:01 -07:00
Walter Bright
bc3dd0afda Even more scope for FormatSpec 2019-03-18 01:28:47 -07:00
tibi77
7ae2e67a47 Remove redundant body of @disable functions. Issue 14854 DMD (#6893)
Remove redundant body of @disable functions. Issue 14854 DMD
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2019-03-06 02:00:04 +01:00
Bastiaan Veelo
79043ed54a
Remove underscore. 2019-02-21 12:12:57 +01:00