Skip to content

Commit ebc0e0c

Browse files
cache regex in namespace instead of recomputing it at runtime
1 parent adfdf5b commit ebc0e0c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

R/data.table.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ replace_dot_alias = function(e) {
9696
x
9797
}
9898

99+
# a slightly wonky workaround so that this still works in non-English sessions, #4989
100+
# generate this at run time (as opposed to e.g. onAttach) since session language is
101+
# technically OK to update (though this should be rare), and since it's low-cost
102+
# to do so here because we're about to error anyway.
103+
.missing_obj_regex = gsub(
104+
"'____missing_datatable_variable____'",
105+
"'(?<obj_name>[^']+)'",
106+
# expression() to avoid "no visible binding for global variable" note from R CMD check
107+
conditionMessage(tryCatch(eval(expression(`____missing_datatable_variable____`)), error=identity)),
108+
fixed=TRUE
109+
)
99110
.checkTypos = function(err, ref) {
100-
# a slightly wonky workaround so that this still works in non-English sessions, #4989
101-
# generate this at run time (as opposed to e.g. onAttach) since session language is
102-
# technically OK to update (though this should be rare), and since it's low-cost
103-
# to do so here because we're about to error anyway.
104-
missing_obj_fmt = gsub(
105-
"'____missing_datatable_variable____'",
106-
"'(?<obj_name>[^']+)'",
107-
# expression() to avoid "no visible binding for global variable" note from R CMD check
108-
conditionMessage(tryCatch(eval(expression(`____missing_datatable_variable____`)), error=identity)),
109-
fixed=TRUE
110-
)
111-
idx = regexpr(missing_obj_fmt, err$message, perl=TRUE)
111+
idx = regexpr(.missing_obj_regex, err$message, perl=TRUE)
112112
if (idx > 0L) {
113113
start = attr(idx, "capture.start", exact=TRUE)[ , "obj_name"]
114114
used = substr(

0 commit comments

Comments
 (0)