projects
/
mono.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #409 from Alkarex/patch-1
[mono.git]
/
mcs
/
class
/
System.Core
/
System.Linq.Parallel.QueryNodes
/
QueryWhereNode.cs
diff --git
a/mcs/class/System.Core/System.Linq.Parallel.QueryNodes/QueryWhereNode.cs
b/mcs/class/System.Core/System.Linq.Parallel.QueryNodes/QueryWhereNode.cs
index fc6e007678138ad2025816ce6df76fa7faf136e4..fe9ca8a90edfa3c3cd003e19cc5a61cfbec87ff1 100644
(file)
--- a/
mcs/class/System.Core/System.Linq.Parallel.QueryNodes/QueryWhereNode.cs
+++ b/
mcs/class/System.Core/System.Linq.Parallel.QueryNodes/QueryWhereNode.cs
@@
-24,7
+24,7
@@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#if NET_4_0
+#if NET_4_0
|| MOBILE
using System;
using System.Linq;
using System.Threading;
using System;
using System.Linq;
using System.Threading;
@@
-63,14
+63,14
@@
namespace System.Linq.Parallel.QueryNodes
internal override IList<IEnumerable<TSource>> GetEnumerablesIndexed (QueryOptions options)
{
return Parent.GetOrderedEnumerables (options)
internal override IList<IEnumerable<TSource>> GetEnumerablesIndexed (QueryOptions options)
{
return Parent.GetOrderedEnumerables (options)
- .Select (
(i) => i.Where ((e) => indexedPredicate (e.Value, (int)e.Key)).Select ((e)
=> e.Value))
+ .Select (
i => i.Where (e => indexedPredicate (e.Value, (int)e.Key)).Select (e
=> e.Value))
.ToList ();
}
internal override IList<IEnumerable<TSource>> GetEnumerablesNonIndexed (QueryOptions options)
{
return Parent.GetEnumerables (options)
.ToList ();
}
internal override IList<IEnumerable<TSource>> GetEnumerablesNonIndexed (QueryOptions options)
{
return Parent.GetEnumerables (options)
- .Select (
(i)
=> i.Where (predicate))
+ .Select (
i
=> i.Where (predicate))
.ToList ();
}
.ToList ();
}
@@
-78,20
+78,18
@@
namespace System.Linq.Parallel.QueryNodes
{
IList<IEnumerable<KeyValuePair<long, TSource>>> sources = Parent.GetOrderedEnumerables (options);
{
IList<IEnumerable<KeyValuePair<long, TSource>>> sources = Parent.GetOrderedEnumerables (options);
- Tuple<TSource, long, bool>[] store = new Tuple<TSource, long, bool>[sources.Count];
+ ProcessingSlot[] store = new ProcessingSlot[sources.Count];
+ Comparison<ProcessingSlot> arrayComparison = ArraySortMethod;
long lastIndex = 0;
Barrier barrier = new Barrier (sources.Count, delegate (Barrier b) {
// Sort the store
long lastIndex = 0;
Barrier barrier = new Barrier (sources.Count, delegate (Barrier b) {
// Sort the store
- Array.Sort (store,
ArraySortMethod
);
+ Array.Sort (store,
arrayComparison
);
// Reassign a good index
int i = 0;
// Reassign a good index
int i = 0;
-
- for (i = 0; i < store.Length && store[i].Item3; i++) {
- Tuple<TSource, long, bool> old = store[i];
- store[i] = Tuple.Create (old.Item1, lastIndex + i, old.Item3);
- }
+ for (i = 0; i < store.Length && store[i].IsValid; ++i)
+ store[i].Index = lastIndex + i;
// Update lastIndex for next round
lastIndex += i;
// Update lastIndex for next round
lastIndex += i;
@@
-102,43
+100,42
@@
namespace System.Linq.Parallel.QueryNodes
.ToList ();
}
.ToList ();
}
- static int ArraySortMethod (
Tuple<TSource, long, bool> lhs, Tuple<TSource, long, bool>
rhs)
+ static int ArraySortMethod (
ProcessingSlot lhs, ProcessingSlot
rhs)
{
{
- if (lhs.I
tem3 && !rhs.Item3
)
+ if (lhs.I
sValid && !rhs.IsValid
)
return -1;
return -1;
- if (!lhs.I
tem3 && rhs.Item3
)
+ if (!lhs.I
sValid && rhs.IsValid
)
return 1;
return 1;
- if (!lhs.I
tem3 && !rhs.Item3
)
+ if (!lhs.I
sValid && !rhs.IsValid
)
return 0;
return 0;
- return
(lhs.Item2 < rhs.Item2)
? -1 : 1;
+ return
lhs.Index < rhs.Index
? -1 : 1;
}
IEnumerable<KeyValuePair<long, TSource>> GetEnumerator (IEnumerable<KeyValuePair<long, TSource>> source,
Barrier barrier,
CancellationToken token,
}
IEnumerable<KeyValuePair<long, TSource>> GetEnumerator (IEnumerable<KeyValuePair<long, TSource>> source,
Barrier barrier,
CancellationToken token,
-
Tuple<TSource, long, bool>
[] store, int index)
+
ProcessingSlot
[] store, int index)
{
IEnumerator<KeyValuePair<long, TSource>> current = source.GetEnumerator ();
{
IEnumerator<KeyValuePair<long, TSource>> current = source.GetEnumerator ();
- bool result;
- Tuple<TSource, long, bool> reset = Tuple.Create (default (TSource), long.MaxValue, false);
+ bool isIndexed = IsIndexed;
try {
while (current.MoveNext ()) {
KeyValuePair<long, TSource> curr = current.Current;
try {
while (current.MoveNext ()) {
KeyValuePair<long, TSource> curr = current.Current;
-
result = I
sIndexed ? indexedPredicate (curr.Value, (int)curr.Key) : predicate (curr.Value);
- store[index]
= Tuple.Cre
ate (curr.Value, curr.Key, result);
+
bool result = i
sIndexed ? indexedPredicate (curr.Value, (int)curr.Key) : predicate (curr.Value);
+ store[index]
.Upd
ate (curr.Value, curr.Key, result);
barrier.SignalAndWait (token);
barrier.SignalAndWait (token);
-
Tuple<TSource, long, bool>
value = store [index];
+
var
value = store [index];
- if (value.I
tem3
)
- yield return new KeyValuePair<long, TSource> (value.I
tem2, value.Item1
);
+ if (value.I
sValid
)
+ yield return new KeyValuePair<long, TSource> (value.I
ndex, value.Value
);
// Reset
// Reset
- store[index]
= reset
;
+ store[index]
.Clear ()
;
}
} finally {
// Remove our participation
}
} finally {
// Remove our participation
@@
-146,6
+143,25
@@
namespace System.Linq.Parallel.QueryNodes
current.Dispose ();
}
}
current.Dispose ();
}
}
+
+ struct ProcessingSlot
+ {
+ public TSource Value;
+ public long Index;
+ public bool IsValid;
+
+ public void Update (TSource v, long i, bool t)
+ {
+ Value = v;
+ Index = i;
+ IsValid = t;
+ }
+
+ public void Clear ()
+ {
+ Update (default (TSource), long.MaxValue, false);
+ }
+ }
}
}
#endif
}
}
#endif