MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / parse_with_cache

Method parse_with_cache

src/Chain/libraries/glua/lparsercombinator.cpp:773–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

771 }
772
773 ParseResult ParserContext::parse_with_cache(ParserFunctor *parser, Input &input, size_t skip_end_size, bool optional)
774 {
775 size_t MAX_SIZE_AFTER_MAX_TOKENS_COUNT = 100000; // TODO: 这里要用input的pos和skip_end_size来cache,暂时用pos + skip_end_size * MAX_SIZE_AFTER_MAX_TOKENS_COUNT
776 size_t size_key = input.pos() + skip_end_size * MAX_SIZE_AFTER_MAX_TOKENS_COUNT;
777 auto found = _parsers_parse_result_cache.find(parser);
778 if (found == _parsers_parse_result_cache.end())
779 {
780 _parsers_parse_result_cache[parser] = std::make_shared<std::unordered_map<size_t, ParseResult>>();
781 found = _parsers_parse_result_cache.find(parser);
782 }
783 auto parser_result_map = found->second;
784 auto found2 = parser_result_map->find(size_key);
785 if (PARSING_MAX_LEVEL_DEPTH > 10 && _parsing_level > PARSING_MAX_LEVEL_DEPTH - 5)
786 {
787 // 如果是因为parsing_level导致的failure,不应该记录到cache
788 return parser->tryParse(input, skip_end_size, optional);
789 }
790 else if (found2 == parser_result_map->end())
791 {
792 auto pr = parser->tryParse(input, skip_end_size, optional);
793 (*parser_result_map)[size_key] = pr;
794 return pr;
795 }
796 else
797 {
798 return found2->second;
799 }
800 }
801
802 ParserFunctor *ParserFunctor::set_result_requirement(std::function<bool(Input &, MatchResult*)> fn)
803 {

Callers 2

tryParseMethod · 0.80

Calls 4

posMethod · 0.45
findMethod · 0.45
endMethod · 0.45
tryParseMethod · 0.45

Tested by

no test coverage detected