Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Page.cs « Storage « TextModel « Impl « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52563737c62a544571252030753ebf93e7ef62e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
// This file contain implementations details that are subject to change without notice.
// Use at your own risk.
//
using System;
using System.Diagnostics;
namespace Microsoft.VisualStudio.Text.Implementation
{
    /// <summary>
    /// Base class for a page that participates in an MRU list.
    /// </summary>
    internal class Page
    {
        private WeakReference<char[]> _uncompressedContents;
        private byte[] _compressedContents;

        public readonly int Length;
        public readonly PageManager Manager;

        public Page(PageManager manager, char[] contents, int length)
        {
            this.Manager = manager;
            this.Length = length;

            _uncompressedContents = new WeakReference<char[]>(contents);
            _compressedContents = Compressor.Compress(contents, length);
        }

        public char[] Expand()
        {
            char[] contents;
            if (!_uncompressedContents.TryGetTarget(out contents))
            {
                contents = new char[this.Length];
                Compressor.Decompress(_compressedContents, this.Length, contents);

                _uncompressedContents.SetTarget(contents);
            }

            this.Manager.UpdateMRU(this);
            return contents;

        }
    }
}