/// <summary> /// Discards loaded pages up to the specified token index. /// </summary> /// <param name="index">The index of the first token to preserve.</param> /// <returns>true if pages were trimmed; otherwise, false.</returns> public Boolean Trim(Int32 index) { if (index < offset || pageCount == 0) { return(false); } var pageIndex = (index - offset) / UvssLexerStreamPage.Size; if (pageIndex == 0 || pageIndex >= pageCount) { return(false); } pageCount = pageCount - pageIndex; Array.Copy(pages, pageIndex, pages, 0, pageCount); for (int i = pageCount; i < pages.Length; i++) { pages[i] = new UvssLexerStreamPage(); } offset += pageIndex * UvssLexerStreamPage.Size; return(true); }
/// <summary> /// Ensures that the stream's array of pages has at least /// the specified capacity. /// </summary> /// <param name="capacity">The requested capacity.</param> private void EnsurePageCapacity(Int32 capacity) { if (pages == null) { if (capacity < 4) { capacity = 4; } pages = new UvssLexerStreamPage[capacity]; } else { if (capacity <= pages.Length) { return; } var size = Math.Max(capacity, pages.Length * 2); var temp = new UvssLexerStreamPage[size]; Array.Copy(pages, temp, pageCount); pages = temp; } for (int i = 0; i < pages.Length; i++) { if (pages[i] == null) { pages[i] = new UvssLexerStreamPage(); } } }
/// <summary> /// Ensures that the stream's array of pages has at least /// the specified capacity. /// </summary> /// <param name="capacity">The requested capacity.</param> private void EnsurePageCapacity(Int32 capacity) { if (pages == null) { if (capacity < 4) capacity = 4; pages = new UvssLexerStreamPage[capacity]; } else { if (capacity <= pages.Length) return; var size = Math.Max(capacity, pages.Length * 2); var temp = new UvssLexerStreamPage[size]; Array.Copy(pages, temp, pageCount); pages = temp; } for (int i = 0; i < pages.Length; i++) { if (pages[i] == null) pages[i] = new UvssLexerStreamPage(); } }
/// <summary> /// Discards loaded pages up to the specified token index. /// </summary> /// <param name="index">The index of the first token to preserve.</param> /// <returns>true if pages were trimmed; otherwise, false.</returns> public Boolean Trim(Int32 index) { if (index < offset || pageCount == 0) return false; var pageIndex = (index - offset) / UvssLexerStreamPage.Size; if (pageIndex == 0 || pageIndex >= pageCount) return false; pageCount = pageCount - pageIndex; Array.Copy(pages, pageIndex, pages, 0, pageCount); for (int i = pageCount; i < pages.Length; i++) pages[i] = new UvssLexerStreamPage(); offset += pageIndex * UvssLexerStreamPage.Size; return true; }