Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #284 from 9rnsr/fix6208_on_inout""
Browse files Browse the repository at this point in the history
This reverts commit fef20ed.
  • Loading branch information
9rnsr committed Dec 15, 2011
1 parent 27d5ca8 commit 17e87a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
15 changes: 8 additions & 7 deletions std/array.d
Expand Up @@ -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;
Expand Down Expand Up @@ -1802,23 +1804,22 @@ 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[]
assert(overlap(s, slice) is slice);
}
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
Expand Down
8 changes: 7 additions & 1 deletion std/exception.d
Expand Up @@ -778,7 +778,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))
{
Expand All @@ -804,6 +804,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
{
Expand Down
10 changes: 5 additions & 5 deletions std/parallelism.d
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 17e87a4

Please sign in to comment.