From 2214034d039a46b419a1bdf052d561f7d5b1e86e Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Thu, 6 Apr 2017 07:04:47 -0700 Subject: [PATCH] [QualifiedName] Don't compute regex in each of_qual_string call Reviewed By: jberdine Differential Revision: D4843262 fbshipit-source-id: 246692c --- infer/src/IR/QualifiedCppName.re | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/infer/src/IR/QualifiedCppName.re b/infer/src/IR/QualifiedCppName.re index cea97502d..ad5acf509 100644 --- a/infer/src/IR/QualifiedCppName.re +++ b/infer/src/IR/QualifiedCppName.re @@ -37,14 +37,13 @@ let of_rev_list = ident; let cpp_separator = "::"; +/* define [cpp_separator_regex] here to compute it once */ +let cpp_separator_regex = Str.regexp_string cpp_separator; + /* This is simplistic and will give the wrong answer in some cases, eg "foo>::someMethod" will get parsed as ["foo>", "someMethod"]. Avoid using it if possible */ -let of_qual_string str => { - let class_sep_regex = Str.regexp_string cpp_separator; - /* wait until here to define the function so that [class_sep_regex] is only computed once */ - Str.split class_sep_regex str |> List.rev -}; +let of_qual_string str => Str.split cpp_separator_regex str |> List.rev; let to_separated_string quals sep::sep => List.rev quals |> String.concat sep::sep;