// Helper for InsertText. Inserts text to the right of an existing block. private static void InsertTextRight(TextTreeTextBlock leftBlock, object text, int textOffset) { int newBlockCount; TextTreeTextBlock rightBlock; TextTreeTextBlock neighborBlock; TextTreeTextBlock newBlock; int count; int textEndOffset; int i; textEndOffset = TextContainer.GetTextLength(text); if (leftBlock.GapOffset == leftBlock.Count) { // Try to fill neighbor block. neighborBlock = (TextTreeTextBlock)leftBlock.GetNextNode(); if (neighborBlock != null) { count = Math.Min(neighborBlock.FreeCapacity, textEndOffset - textOffset); neighborBlock.InsertText(0, text, textEndOffset - count, textEndOffset); textEndOffset -= count; } } if (textOffset < textEndOffset) { // Try adding just one block. newBlockCount = 1; rightBlock = leftBlock.SplitBlock(); // Fill up the right block. count = Math.Min(rightBlock.FreeCapacity, textEndOffset - textOffset); rightBlock.InsertText(0, text, textEndOffset - count, textEndOffset); textEndOffset -= count; if (textOffset < textEndOffset) { // Fill up the larger block. // We need to copy from the end of the text here. textOffset += leftBlock.InsertText(leftBlock.Count, text, textOffset, textEndOffset); if (textOffset < textEndOffset) { // We've filled both blocks, and there's still more text to copy. // Prepare to allocate some more blocks. newBlockCount += (textEndOffset - textOffset + TextTreeTextBlock.MaxBlockSize - 1) / TextTreeTextBlock.MaxBlockSize; } } for (i = 0; i < newBlockCount - 1; i++) { newBlock = new TextTreeTextBlock(TextTreeTextBlock.MaxBlockSize); textOffset += newBlock.InsertText(0, text, textOffset, textEndOffset); newBlock.InsertAtNode(leftBlock, false /* insertBefore */); leftBlock = newBlock; } Invariant.Assert(textOffset == textEndOffset, "Not all text copied!"); } }
// Token: 0x06003DC8 RID: 15816 RVA: 0x0011CB6C File Offset: 0x0011AD6C internal TextTreeTextBlock SplitBlock() { Invariant.Assert(this._gapSize == 0, "Splitting non-full block!"); Invariant.Assert(this._text.Length == 4096, "Splitting non-max sized block!"); TextTreeTextBlock textTreeTextBlock = new TextTreeTextBlock(4096); bool insertBefore; if (this._gapOffset < 2048) { Array.Copy(this._text, 0, textTreeTextBlock._text, 0, this._gapOffset); textTreeTextBlock._gapOffset = this._gapOffset; textTreeTextBlock._gapSize = 4096 - this._gapOffset; this._gapSize += this._gapOffset; this._gapOffset = 0; insertBefore = true; } else { Array.Copy(this._text, this._gapOffset, textTreeTextBlock._text, this._gapOffset, 4096 - this._gapOffset); Invariant.Assert(textTreeTextBlock._gapOffset == 0); textTreeTextBlock._gapSize = this._gapOffset; this._gapSize = 4096 - this._gapOffset; insertBefore = false; } textTreeTextBlock.InsertAtNode(this, insertBefore); return(textTreeTextBlock); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors // Creates a TextTreeRootTextBlock instance. internal TextTreeRootTextBlock() { TextTreeTextBlock block; // Allocate an initial block with just two characters -- one for // each edge of the root node. The block will grow when/if // additional content is added. block = new TextTreeTextBlock(2); block.InsertAtNode(this, ElementEdge.AfterStart); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors // Creates a TextTreeRootTextBlock instance. internal TextTreeRootTextBlock() { TextTreeTextBlock block; // Allocate an initial block with just two characters -- one for // each edge of the root node. The block will grow when/if // additional content is added. block = new TextTreeTextBlock(2); block.InsertAtNode(this, ElementEdge.AfterStart); }
// Splits this block at the current gap offset. // Only called during a text insert, when the block is full. // If GapOffset < TextTreeTextBlock.MaxBlockSize / 2, returns // a new block with the left text, otherwise returns a new // block with the right text. internal TextTreeTextBlock SplitBlock() { TextTreeTextBlock newBlock; bool insertBefore; Invariant.Assert(_gapSize == 0, "Splitting non-full block!"); Invariant.Assert(_text.Length == MaxBlockSize, "Splitting non-max sized block!"); newBlock = new TextTreeTextBlock(MaxBlockSize); if (_gapOffset < MaxBlockSize / 2) { // Copy the left text over to the new block. Array.Copy(_text, 0, newBlock._text, 0, _gapOffset); newBlock._gapOffset = _gapOffset; newBlock._gapSize = MaxBlockSize - _gapOffset; // Remove the left text from this block. _gapSize += _gapOffset; _gapOffset = 0; // New node preceeds this one. insertBefore = true; } else { // Copy the right text over to the new block. Array.Copy(_text, _gapOffset, newBlock._text, _gapOffset, MaxBlockSize - _gapOffset); Invariant.Assert(newBlock._gapOffset == 0); newBlock._gapSize = _gapOffset; // Remove the left text from this block. _gapSize = MaxBlockSize - _gapOffset; // New node follows this one. insertBefore = false; } // Add the new node to the splay tree. newBlock.InsertAtNode(this, insertBefore); return(newBlock); }
// Token: 0x06003DAF RID: 15791 RVA: 0x0011C7F8 File Offset: 0x0011A9F8 private static void InsertTextRight(TextTreeTextBlock leftBlock, object text, int textOffset) { int num = TextContainer.GetTextLength(text); if (leftBlock.GapOffset == leftBlock.Count) { TextTreeTextBlock textTreeTextBlock = (TextTreeTextBlock)leftBlock.GetNextNode(); if (textTreeTextBlock != null) { int num2 = Math.Min(textTreeTextBlock.FreeCapacity, num - textOffset); textTreeTextBlock.InsertText(0, text, num - num2, num); num -= num2; } } if (textOffset < num) { int num3 = 1; TextTreeTextBlock textTreeTextBlock2 = leftBlock.SplitBlock(); int num2 = Math.Min(textTreeTextBlock2.FreeCapacity, num - textOffset); textTreeTextBlock2.InsertText(0, text, num - num2, num); num -= num2; if (textOffset < num) { textOffset += leftBlock.InsertText(leftBlock.Count, text, textOffset, num); if (textOffset < num) { num3 += (num - textOffset + 4096 - 1) / 4096; } } for (int i = 0; i < num3 - 1; i++) { TextTreeTextBlock textTreeTextBlock3 = new TextTreeTextBlock(4096); textOffset += textTreeTextBlock3.InsertText(0, text, textOffset, num); textTreeTextBlock3.InsertAtNode(leftBlock, false); leftBlock = textTreeTextBlock3; } Invariant.Assert(textOffset == num, "Not all text copied!"); } }
// Token: 0x06003DAE RID: 15790 RVA: 0x0011C700 File Offset: 0x0011A900 private static void InsertTextLeft(TextTreeTextBlock rightBlock, object text, int textOffset) { int num = -1; int textLength = TextContainer.GetTextLength(text); if (rightBlock.GapOffset == 0) { TextTreeTextBlock textTreeTextBlock = (TextTreeTextBlock)rightBlock.GetPreviousNode(); if (textTreeTextBlock != null) { textOffset += textTreeTextBlock.InsertText(textTreeTextBlock.Count, text, textOffset, textLength); } } if (textOffset < textLength) { int num2 = 1; TextTreeTextBlock textTreeTextBlock2 = rightBlock.SplitBlock(); textOffset += textTreeTextBlock2.InsertText(textTreeTextBlock2.Count, text, textOffset, textLength); if (textOffset < textLength) { int num3 = Math.Min(rightBlock.FreeCapacity, textLength - textOffset); num = textLength - num3; rightBlock.InsertText(0, text, num, textLength); if (textOffset < num) { num2 += (num - textOffset + 4096 - 1) / 4096; } } for (int i = 1; i < num2; i++) { TextTreeTextBlock textTreeTextBlock3 = new TextTreeTextBlock(4096); textOffset += textTreeTextBlock3.InsertText(0, text, textOffset, num); textTreeTextBlock3.InsertAtNode(textTreeTextBlock2, false); textTreeTextBlock2 = textTreeTextBlock3; } Invariant.Assert(num2 == 1 || textOffset == num, "Not all text copied!"); } }
// Splits this block at the current gap offset. // Only called during a text insert, when the block is full. // If GapOffset < TextTreeTextBlock.MaxBlockSize / 2, returns // a new block with the left text, otherwise returns a new // block with the right text. internal TextTreeTextBlock SplitBlock() { TextTreeTextBlock newBlock; bool insertBefore; Invariant.Assert(_gapSize == 0, "Splitting non-full block!"); Invariant.Assert(_text.Length == MaxBlockSize, "Splitting non-max sized block!"); newBlock = new TextTreeTextBlock(MaxBlockSize); if (_gapOffset < MaxBlockSize / 2) { // Copy the left text over to the new block. Array.Copy(_text, 0, newBlock._text, 0, _gapOffset); newBlock._gapOffset = _gapOffset; newBlock._gapSize = MaxBlockSize - _gapOffset; // Remove the left text from this block. _gapSize += _gapOffset; _gapOffset = 0; // New node preceeds this one. insertBefore = true; } else { // Copy the right text over to the new block. Array.Copy(_text, _gapOffset, newBlock._text, _gapOffset, MaxBlockSize - _gapOffset); Invariant.Assert(newBlock._gapOffset == 0); newBlock._gapSize = _gapOffset; // Remove the left text from this block. _gapSize = MaxBlockSize - _gapOffset; // New node follows this one. insertBefore = false; } // Add the new node to the splay tree. newBlock.InsertAtNode(this, insertBefore); return newBlock; }
// Helper for InsertText. Inserts text to the right of an existing block. private static void InsertTextRight(TextTreeTextBlock leftBlock, object text, int textOffset) { int newBlockCount; TextTreeTextBlock rightBlock; TextTreeTextBlock neighborBlock; TextTreeTextBlock newBlock; int count; int textEndOffset; int i; textEndOffset = TextContainer.GetTextLength(text); if (leftBlock.GapOffset == leftBlock.Count) { // Try to fill neighbor block. neighborBlock = (TextTreeTextBlock)leftBlock.GetNextNode(); if (neighborBlock != null) { count = Math.Min(neighborBlock.FreeCapacity, textEndOffset - textOffset); neighborBlock.InsertText(0, text, textEndOffset - count, textEndOffset); textEndOffset -= count; } } if (textOffset < textEndOffset) { // Try adding just one block. newBlockCount = 1; rightBlock = leftBlock.SplitBlock(); // Fill up the right block. count = Math.Min(rightBlock.FreeCapacity, textEndOffset - textOffset); rightBlock.InsertText(0, text, textEndOffset - count, textEndOffset); textEndOffset -= count; if (textOffset < textEndOffset) { // Fill up the larger block. // We need to copy from the end of the text here. textOffset += leftBlock.InsertText(leftBlock.Count, text, textOffset, textEndOffset); if (textOffset < textEndOffset) { // We've filled both blocks, and there's still more text to copy. // Prepare to allocate some more blocks. newBlockCount += (textEndOffset - textOffset + TextTreeTextBlock.MaxBlockSize - 1) / TextTreeTextBlock.MaxBlockSize; } } for (i=0; i<newBlockCount-1; i++) { newBlock = new TextTreeTextBlock(TextTreeTextBlock.MaxBlockSize); textOffset += newBlock.InsertText(0, text, textOffset, textEndOffset); newBlock.InsertAtNode(leftBlock, false /* insertBefore */); leftBlock = newBlock; } Invariant.Assert(textOffset == textEndOffset, "Not all text copied!"); } }
// Token: 0x06003DB1 RID: 15793 RVA: 0x0011C95C File Offset: 0x0011AB5C internal TextTreeRootTextBlock() { TextTreeTextBlock textTreeTextBlock = new TextTreeTextBlock(2); textTreeTextBlock.InsertAtNode(this, ElementEdge.AfterStart); }