Пример #1
0
        /// <summary>
        /// Initializes a new instance of the System.Text.RegularExpressions.Regex class
        /// for the specified regular expression, with options that modify the pattern and
        /// a value that specifies how long a pattern matching method should attempt a match
        /// before it times out.
        /// </summary>
        /// <param name="pattern">The regular expression pattern to match.</param>
        /// <param name="options">A bitwise combination of the enumeration values that modify the regular expression.</param>
        /// <param name="matchTimeout">A time-out interval, or System.Text.RegularExpressions.Regex.InfiniteMatchTimeout to indicate that the method should not time out.</param>
        /// <exception cref="System.ArgumentException">A regular expression parsing error occurred.</exception>
        /// <exception cref="System.ArgumentNullException">pattern is null.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException:">
        /// options is not a valid System.Text.RegularExpressions.RegexOptions value. -or- matchTimeout is negative, zero, or greater than approximately 24 days.
        /// </exception>
        public Regex(string pattern, System.Text.RegularExpressions.RegexOptions?options, TimeSpan?matchTimeout, string poolKey = null, int?poolSize = null)
        {
            if (string.IsNullOrEmpty(pattern))
            {
                throw new ArgumentNullException(nameof(pattern));
            }
            _pattern      = pattern;
            _options      = options;
            _matchTimeout = matchTimeout;

            PoolKey  = poolKey;
            PoolSize = !poolSize.HasValue ? Environment.ProcessorCount * 2 : poolSize.Value;

            var policyHashCode = GetPolicyHashCode(pattern, options, matchTimeout, poolKey);

            performanceObject = null;
            //hasWrapperObject = false;
            wrapperObject   = default;
            IsPoolAllocated = false;
            _objectPool     = null;
            if (!StaticPerformanceBase <System.Text.RegularExpressions.Regex> .PooledObjectPolicyFactoryCollection.ContainsKey(policyHashCode))
            {
                // Add in policy factory into collection.
                StaticPerformanceBase <System.Text.RegularExpressions.Regex> .PooledObjectPolicyFactoryCollection.TryAdd(policyHashCode, getPooledObjectPolicyFactory);
            }
            wrapperObject = StaticPerformanceBase <System.Text.RegularExpressions.Regex> .GetWrapperObject(policyHashCode, PoolSize, out _objectPool);

            performanceObject = wrapperObject.Element;
            IsPoolAllocated   = wrapperObject.Index > -1;
        }
Пример #2
0
 internal void Dispose(bool leavePooledObjectContents)
 {
     // Only need to Dispose if it's been allocated from the pool.
     if (IsPoolAllocated)
     {
         StaticPerformanceBase <System.Text.RegularExpressions.Regex> .Dispose(_objectPool, wrapperObject);
     }
 }
Пример #3
0
 public void ResetItemCounter()
 {
     StaticPerformanceBase <T> .resetItemCounter();
 }
Пример #4
0
 public void DisposeAll()
 {
     StaticPerformanceBase <T> .disposeAll();
 }
Пример #5
0
 public void Dispose()
 {
     StaticPerformanceBase <T> .reset();
 }