From b7b4f63bbc271d9c491e7639e9a0117cd19d4ec8 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 9 Sep 2021 18:53:36 -0700 Subject: [PATCH] [PyTorch] Use std::find in the JIT lexer (#64652) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/64652 If nothing else, it is slightly clearer code. ghstack-source-id: 137608456 Test Plan: CI Reviewed By: dhruvbird Differential Revision: D30739239 fbshipit-source-id: bc7917b59883ca4a33fc6916b4e422bad79cf04b --- torch/csrc/jit/frontend/lexer.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/torch/csrc/jit/frontend/lexer.h b/torch/csrc/jit/frontend/lexer.h index 63041c3..c2bd32f 100644 --- a/torch/csrc/jit/frontend/lexer.h +++ b/torch/csrc/jit/frontend/lexer.h @@ -337,16 +337,12 @@ struct TORCH_API SharedParserData { // rather the // identifier 'max' if (cur) { - size_t child_offset = 0; - for (size_t e = cur->child_chars.size(); child_offset < e; - ++child_offset) { - if (cur->child_chars[child_offset] == str[pos + i]) - break; - } + const auto begin_it = cur->child_chars.begin(); + const auto end_it = cur->child_chars.end(); + const auto ch_it = std::find(begin_it, end_it, str[pos + i]); - cur = (child_offset == cur->child_chars.size()) - ? nullptr - : cur->child_tries[child_offset].get(); + cur = (ch_it == end_it) ? nullptr + : cur->child_tries[ch_it - begin_it].get(); if (cur && cur->kind != 0) { matched = true; -- 2.7.4