예제 #1
0
        private void UpdateLogEntryIndicesNoLock(MergedLogFileChanges changes)
        {
            // DO NOT CALL EXTERNAL / VIRTUAL METHODS OF ANY KIND HERE

            // We only need to re-calculate those indices if there was an invalidation or a portion
            // of this index. If there wasn't, then ProcessAppendsNoLock() already does its job as required...
            if (changes.TryGetFirstInvalidationIndex(out var firstInvalidatedIndex))
            {
                for (int i = firstInvalidatedIndex.Value; i < _indices.Count; ++i)
                {
                    var index = _indices[i];
                    index.MergedLogEntryIndex = (int)CalculateLogEntryIndexFor(i, index);
                    _indices[i] = index;
                }
            }
        }
예제 #2
0
        private void ProcessAppendsNoLock(IReadOnlyList <MergedLogFileSection> pendingModifications, MergedLogFileChanges changes)
        {
            // DO NOT CALL EXTERNAL / VIRTUAL METHODS OF ANY KIND HERE

            var indices = CreateIndices(pendingModifications);

            var invalidated         = false;
            var appendStartingIndex = _indices.Count;

            foreach (var index in indices)
            {
                var insertionIndex = FindInsertionIndexNoLock(index);
                if (insertionIndex < _indices.Count)
                {
                    if (!invalidated)
                    {
                        // Here's the awesome thing: We're inserting a "pre-sorted" list of indices
                        // into our index buffer. Therefore, the very first index which requires an invalidation
                        // is also the LOWEST POSSIBLE index which could require an invalidation and therefore
                        // there can only ever be one invalidation while this method is executing.

                        // We do need to take into account that even though we're invalidating a region,
                        // that doesn't mean we also didn't append something previously....
                        var appendCount = _indices.Count - appendStartingIndex;
                        if (appendCount > 0)
                        {
                            changes.Append(appendStartingIndex, appendCount);
                        }

                        changes.InvalidateFrom(insertionIndex);
                        invalidated = true;
                    }
                }

                var actualIndex = index;
                actualIndex.MergedLogEntryIndex = (int)CalculateLogEntryIndexFor(insertionIndex, index);
                _indices.Insert(insertionIndex, actualIndex);
            }

            var appendCount2 = _indices.Count - appendStartingIndex;

            if (appendCount2 > 0)
            {
                changes.Append(appendStartingIndex, appendCount2);
            }
        }
예제 #3
0
        private void ProcessResetsNoLock(IReadOnlyList <MergedLogFileSection> pendingModifications, MergedLogFileChanges changes)
        {
            // DO NOT CALL EXTERNAL / VIRTUAL METHODS OF ANY KIND HERE

            foreach (var pendingModification in pendingModifications)
            {
                if (pendingModification.Section.IsReset)
                {
                    var logFileIndex = GetLogFileIndex(pendingModification.LogFile);
                    var firstIndex   = _indices.FindIndex(x => x.LogFileIndex == logFileIndex);
                    if (firstIndex >= 0)
                    {
                        changes.InvalidateFrom(firstIndex);
                        _indices.RemoveAll(x => x.LogFileIndex == logFileIndex);
                        if (_indices.Count == 0)
                        {
                            changes.Reset();
                        }
                    }
                }
            }
        }