public IStreamReader <T> GetReader() { if (FNodeIn.IsConvoluted) { return(new ConvolutedReader(FUpstreamStream, FLength, FUpStreamSlices)); } return(FUpstreamStream.GetReader()); }
public void Evaluate(int spreadMax) { // The final output length is known in advance Output.Length = spreadMax; // Whether or not new slices should be initialized with true var bangOnCreate = BangOnCreateIn.SliceCount > 0 ? BangOnCreateIn[0] : false; // Fetch readers and writers var inputReader = Input.GetReader(); var lastInputReader = FLastInput.GetReader(); var lastInputWriter = FLastInput.GetDynamicWriter(); var outputWriter = Output.GetWriter(); // In case of very low spread counts this saves a few ticks if (spreadMax < 16) { var slicesToWrite = spreadMax; var inputLength = inputReader.Length; var lastInputLength = lastInputReader.Length; var minLength = Math.Min(inputLength, lastInputLength); for (int i = 0; i < minLength; i++) { var input = inputReader.Read(); var lastInput = lastInputReader.Read(); var changed = !FComparer.Equals(input, lastInput); outputWriter.Write(changed); lastInputWriter.Write(CopySlice(input)); } for (int i = lastInputLength; i < inputLength; i++) { var changed = bangOnCreate; outputWriter.Write(changed); var input = inputReader.Read(); lastInputWriter.Write(CopySlice(input)); } } else { // Fetch the buffers to work with from the pool var inputBuffer = MemoryPool <T> .GetArray(); var lastInputBuffer = MemoryPool <T> .GetArray(); var outputBuffer = MemoryPool <bool> .GetArray(); try { var slicesToWrite = spreadMax; while (slicesToWrite > 0) { // Read the input var inputReadCount = inputReader.Read(inputBuffer, 0, inputBuffer.Length); // Read the input from the previous frame var lastInputReadCount = lastInputReader.Read(lastInputBuffer, 0, lastInputBuffer.Length); // Calculate min and max read counts var minCount = Math.Min(inputReadCount, lastInputReadCount); var maxCount = Math.Max(inputReadCount, lastInputReadCount); // Do the equality check for all the slices where values from // the previous frame are available for (int i = 0; i < minCount; i++) { outputBuffer[i] = !FComparer.Equals(inputBuffer[i], lastInputBuffer[i]); } // Set the output for new slices to the value of bang on create for (int i = minCount; i < maxCount; i++) { outputBuffer[i] = bangOnCreate; } // Write the result outputWriter.Write(outputBuffer, 0, maxCount); // Store the input values for the next frame CopySlices(inputBuffer, inputReadCount); lastInputWriter.Write(inputBuffer, 0, inputReadCount); // Decrease the number of slices we still need to look at slicesToWrite -= maxCount; } } finally { // Put the buffers back in the pool MemoryPool <T> .PutArray(inputBuffer); MemoryPool <T> .PutArray(lastInputBuffer); MemoryPool <bool> .PutArray(outputBuffer); } } // Dispose the readers and writers inputReader.Dispose(); lastInputReader.Dispose(); lastInputWriter.Dispose(); outputWriter.Dispose(); }
public IStreamReader <IInStream <T> > GetReader() { return(FStreams.GetReader()); }
// Called sequentially for all VL plugins on main thread public void SyncPinsAndRestoreState(BuildResult buildResult, HotSwapper swapper) { if (buildResult == FBuildResult) { return; // Same build result, nothing to do } if (buildResult == null) { return; // Something went seriously wrong during compile phase } if (buildResult.ClrMethodToCall == null) { FBuildResult = buildResult; return; // Something went wrong during compile phase } if (buildResult.Compilation.Age < FBuildResult.Compilation?.Age) { return; // Dismiss outdated builds } if (buildResult.ClrMethodToCall == FBuildResult.ClrMethodToCall) { // Same CLR method, nothing to do except for remember the new result // Holding on to the old would introduce a memory leak as old solutions and compilation could not get garbage collected FBuildResult = buildResult; return; } try { // Synchronize pins SyncPins(buildResult); // Restore the state if (FInstances.Length > 0) { var instanceType = buildResult.InstanceType; using (var reader = FInstances.GetReader()) using (var writer = FInstances.GetWriter()) { while (!reader.Eos) { var oldInstance = reader.Read(); if (oldInstance != null) { var newInstance = swapper.Swap(oldInstance, buildResult.Scope, buildResult.Factory); writer.Write(newInstance); } else { var newInstance = instanceType != null?buildResult.Factory.CreateInstance(instanceType, FInstanceId) : null; writer.Write(newInstance); } } } } } catch (Exception exception) { LogException(exception); throw; } finally { FBuildResult = buildResult; } }