예제 #1
0
        private void InternalExpand(int expandMinSize)
        {
            if (hGlobal.Count == HGlobalCache <char> .MaxSize && textWriter != null && offset != 0)
            {
                VersionDifferences.WriteChars(textWriter, hGlobal.GetPointer(), offset);

                offset = 0;

                Expand(expandMinSize);
            }
            else
            {
                hGlobal.Expand(expandMinSize);
            }
        }
예제 #2
0
        private void InternalExpand(int expandMinSize)
        {
            if (HGCache.Capacity == HGlobalCache <char> .MaxSize && TextWriter != null && offset != 0)
            {
                HGCache.Count = offset;

                HGCache.WriteTo(TextWriter);

                offset = 0;

                Expand(expandMinSize);
            }
            else
            {
                HGCache.Expand(expandMinSize);
            }
        }
예제 #3
0
        public void Expand(int expandMinSize)
        {
Loop:
            if (hGlobal.count - offset < expandMinSize)
            {
                if (hGlobal.count == HGlobalCache.MaxSize && textWriter != null && offset != 0)
                {
                    VersionDifferences.WriteChars(textWriter, hGlobal.chars, offset);

                    offset = 0;

                    goto Loop;
                }
                else
                {
                    hGlobal.Expand(expandMinSize);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 将 Stream 的内容缓存到 HGlobalCache 中。
        /// </summary>
        /// <param name="hGCache">HGlobalCache</param>
        /// <param name="stream">Stream</param>
        /// <param name="encoding">编码</param>
        /// <returns>返回缓冲的长度</returns>
        public static void ReadFrom(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding)
        {
            var hGBytes = BytesPool.Rent();

            hGBytes.ReadFrom(stream);

            var maxCharsCount = encoding.GetMaxCharCount(hGBytes.Count);

            if (maxCharsCount >= hGCache.Capacity)
            {
                hGCache.Expand(maxCharsCount);
            }

            hGCache.Count = encoding.GetChars(
                hGBytes.GetPointer(),
                hGBytes.Count,
                hGCache.GetPointer(),
                hGCache.Capacity);

            BytesPool.Return(hGBytes);
        }
예제 #5
0
        /// <summary>
        /// 异步将 Stream 的内容缓存到 HGlobalCache 中。
        /// </summary>
        /// <param name="hGCache">HGlobalCache</param>
        /// <param name="stream">Stream</param>
        /// <param name="encoding">编码</param>
        /// <returns>返回缓冲的长度</returns>
        public static async Task ReadFromAsync(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding)
        {
            var hGBytes = BytesPool.Rent();

            await hGBytes.ReadFromAsync(stream);

            var maxCharsCount = encoding.GetMaxCharCount(hGBytes.Count);

            if (maxCharsCount > hGCache.Capacity)
            {
                hGCache.Expand(maxCharsCount - hGCache.Capacity);
            }

            unsafe
            {
                hGCache.Count = encoding.GetChars(
                    hGBytes.GetPointer(),
                    hGBytes.Count,
                    hGCache.GetPointer(),
                    hGCache.Capacity);
            }

            BytesPool.Return(hGBytes);
        }