diff --git a/std/array.d b/std/array.d index fe9679415..8252e1fd7 100644 --- a/std/array.d +++ b/std/array.d @@ -538,10 +538,12 @@ b = b.dup; assert(overlap(a, b).empty); ---- */ -T[] overlap(T)(T[] r1, T[] r2) @trusted pure nothrow +inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) @trusted pure nothrow { - static T* max(T* a, T* b) nothrow { return a > b ? a : b; } - static T* min(T* a, T* b) nothrow { return a < b ? a : b; } + alias inout(T) U; + static U* max(U* a, U* b) nothrow { return a > b ? a : b; } + static U* min(U* a, U* b) nothrow { return a < b ? a : b; } + auto b = max(r1.ptr, r2.ptr); auto e = min(r1.ptr + r1.length, r2.ptr + r2.length); return b < e ? b[0 .. e - b] : null; @@ -1809,7 +1811,7 @@ unittest Returns an array that is $(D s) with $(D slice) replaced by $(D replacement[]). +/ -T[] replaceSlice(T)(T[] s, in T[] slice, in T[] replacement) +inout(T)[] replaceSlice(T)(inout(T)[] s, in T[] slice, in T[] replacement) in { // Verify that slice[] really is a slice of s[] @@ -1817,15 +1819,14 @@ in } body { - auto result = new Unqual!(typeof(s[0]))[ - s.length - slice.length + replacement.length]; + auto result = new T[s.length - slice.length + replacement.length]; immutable so = slice.ptr - s.ptr; result[0 .. so] = s[0 .. so]; result[so .. so + replacement.length] = replacement; result[so + replacement.length .. result.length] = s[so + slice.length .. s.length]; - return cast(T[]) result; + return cast(inout(T)[]) result; } unittest diff --git a/std/exception.d b/std/exception.d index fd712ed51..2a4fe3a22 100644 --- a/std/exception.d +++ b/std/exception.d @@ -787,7 +787,7 @@ that points to $(D target)'s representation or somewhere inside it. Note that evaluating $(D pointsTo(x, x)) checks whether $(D x) has internal pointers. */ -bool pointsTo(S, T)(ref const S source, ref const T target) @trusted pure nothrow +bool pointsTo(S, T, Tdummy=void)(ref const S source, ref const T target) @trusted pure nothrow { static if (is(S P : U*, U)) { @@ -813,6 +813,12 @@ bool pointsTo(S, T)(ref const S source, ref const T target) @trusted pure nothro return false; } } +// for shared objects +bool pointsTo(S, T)(ref const shared S source, ref const shared T target) @trusted pure nothrow +{ + alias pointsTo!(shared(S), shared(T), void) ptsTo; // do instantiate explicitly + return ptsTo(source, target); +} unittest { diff --git a/std/parallelism.d b/std/parallelism.d index 950b45764..0eedf185d 100644 --- a/std/parallelism.d +++ b/std/parallelism.d @@ -1436,9 +1436,9 @@ public: } // Effectively -1: chunkIndex + 1 == 0: - size_t workUnitIndex = size_t.max; + shared size_t workUnitIndex = size_t.max; - bool shouldContinue = true; + shared bool shouldContinue = true; void doIt() { scope(failure) { @@ -3029,11 +3029,11 @@ private enum string parallelApplyMixinRandomAccess = q{ // Whether iteration is with or without an index variable. enum withIndex = ParameterTypeTuple!(typeof(dg)).length == 2; - size_t workUnitIndex = size_t.max; // Effectively -1: chunkIndex + 1 == 0 + shared size_t workUnitIndex = size_t.max; // Effectively -1: chunkIndex + 1 == 0 immutable len = range.length; if(!len) return 0; - bool shouldContinue = true; + shared bool shouldContinue = true; void doIt() { scope(failure) { @@ -3087,7 +3087,7 @@ enum string parallelApplyMixinInputRange = q{ // This protects the range while copying it. auto rangeMutex = new Mutex(); - bool shouldContinue = true; + shared bool shouldContinue = true; // The total number of elements that have been popped off range. // This is updated only while protected by rangeMutex;