Skip to content

Commit c936c8d

Browse files
committed
Update IParallelJobProducer.cs
1 parent 875b022 commit c936c8d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

JobScheduler/Utils/IParallelJobProducer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ public struct ParallelJobProducer<T> : IJob where T : struct, IParallelJobProduc
5757
/// <param name="singleThreaded">Whether the job producer should not spawn children</param>
5858
public ParallelJobProducer(int from, int to, T producer, int loopSize = 16, bool onlySingle = false, JobHandle source = default, bool singleThreaded = false)
5959
{
60-
6160
_sourceHandle = source;
6261
_from = from;
6362
_to = to;
6463
_producer = producer;
6564
_onlySingle = onlySingle;
6665
_loopSize = loopSize;
66+
if (to - from == 1)
67+
{
68+
singleThreaded = true; // If the range is only 1, we can just run it single threaded
69+
}
70+
6771
_selfHandle = ParallelForJobCommon.GlobalScheduler!.Schedule(singleThreaded ? this : null);
6872
if (!source.IsNull)
6973
{

0 commit comments

Comments
 (0)