public static async Task <StreamParser> Create( IPositionedMessagesReader owner, CreateParserParams p, TextStreamPositioningParams textStreamPositioningParams, IGlobalSettingsAccessor globalSettings, StrategiesCache strategiesCache) { var parser = new StreamParser(owner, p, textStreamPositioningParams, globalSettings, strategiesCache); await parser.Strategy.ParserCreated(parser.InitialParams); return(parser); }
private StreamParser( IPositionedMessagesReader owner, CreateParserParams p, TextStreamPositioningParams textStreamPositioningParams, IGlobalSettingsAccessor globalSettings, StrategiesCache strategiesCache ) { p.EnsureRangeIsSet(owner); this.InitialParams = p; this.isSequentialReadingParser = (p.Flags & MessagesParserFlag.HintParserWillBeUsedForMassiveSequentialReading) != 0; this.multithreadingDisabled = (p.Flags & MessagesParserFlag.DisableMultithreading) != 0 || globalSettings.MultithreadedParsingDisabled; CreateParsingStrategy(p, textStreamPositioningParams, strategiesCache, out this.Strategy); }
void CreateParsingStrategy( CreateParserParams parserParams, TextStreamPositioningParams textStreamPositioningParams, StrategiesCache strategiesCache, out BaseStrategy strategy) { bool useMultithreadedStrategy; if (multithreadingDisabled) { useMultithreadedStrategy = false; } else if (!isSequentialReadingParser) { useMultithreadedStrategy = false; } else { useMultithreadedStrategy = HeuristicallyDetectWhetherMultithreadingMakesSense(parserParams, textStreamPositioningParams); } //useMultithreadedStrategy = false; Lazy <BaseStrategy> strategyToTryFirst; Lazy <BaseStrategy> strategyToTrySecond; if (useMultithreadedStrategy) { strategyToTryFirst = strategiesCache.MultiThreadedStrategy; strategyToTrySecond = strategiesCache.SingleThreadedStrategy; } else { strategyToTryFirst = strategiesCache.SingleThreadedStrategy; strategyToTrySecond = strategiesCache.MultiThreadedStrategy; } strategy = strategyToTryFirst.Value; if (strategy == null) { strategy = strategyToTrySecond.Value; } }