@@ -5,7 +5,6 @@ module bc.string.string;
5
5
6
6
import bc.core.intrinsics ;
7
7
import bc.core.memory : enforceMalloc, enforceRealloc, heapAlloc, heapDealloc;
8
- import core.atomic : atomicOp;
9
8
import std.range : ElementEncodingType, hasLength, isInputRange;
10
9
import std.traits : ForeachType, isSomeChar, isSomeString, isStaticArray, Unqual;
11
10
// debug import core.stdc.stdio;
@@ -256,7 +255,7 @@ private struct StringImpl(C, RC rc, Zero zero)
256
255
{
257
256
struct Payload
258
257
{
259
- shared size_t refs;
258
+ size_t refs;
260
259
size_t len;
261
260
C[] buf;
262
261
@@ -271,19 +270,16 @@ private struct StringImpl(C, RC rc, Zero zero)
271
270
}
272
271
273
272
// / Copy constructor
274
- this (ref return scope StringImpl rhs) pure @safe
273
+ this (ref return scope inout StringImpl rhs) pure @safe inout
275
274
{
276
- if (rhs.pay)
277
- {
278
- this .pay = rhs.pay;
279
- atomicOp! " +=" (this .pay.refs, 1 );
280
- }
275
+ pay = rhs.pay;
276
+ if (pay) () @trusted { (cast (Payload* )pay).refs++ ; }();
281
277
}
282
278
283
279
// / Destructor
284
280
~this ()
285
281
{
286
- if (pay && atomicOp ! " -= " ( pay.refs, 1 ) == 0 ) heapDealloc(pay);
282
+ if (pay && -- pay.refs == 0 ) heapDealloc(pay);
287
283
}
288
284
}
289
285
else
@@ -678,6 +674,16 @@ auto rcString(C = char, S)(auto ref S str)
678
674
}
679
675
}
680
676
677
+ version (D_Exceptions)
678
+ {
679
+ @(" RCString with Nullable" )
680
+ @nogc @safe unittest
681
+ {
682
+ import std.typecons : Nullable;
683
+ Nullable! RCString sn = RCString(" foo" );
684
+ }
685
+ }
686
+
681
687
@(" rcString" )
682
688
@nogc @safe unittest
683
689
{
0 commit comments