Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
e7b841a1
Unverified
Commit
e7b841a1
authored
3 years ago
by
Rhys Arkins
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: regex cache (#12738)
Co-authored-by:
Michael Kriese
<
michael.kriese@visualon.de
>
parent
e095d5a9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/util/regex.ts
+11
-1
11 additions, 1 deletion
lib/util/regex.ts
with
11 additions
and
1 deletion
lib/util/regex.ts
+
11
−
1
View file @
e7b841a1
...
@@ -5,6 +5,8 @@ import { logger } from '../logger';
...
@@ -5,6 +5,8 @@ import { logger } from '../logger';
let
RegEx
:
RegExpConstructor
;
let
RegEx
:
RegExpConstructor
;
const
cache
=
new
Map
<
string
,
RegExp
>
();
try
{
try
{
// eslint-disable-next-line
// eslint-disable-next-line
const
RE2
=
require
(
'
re2
'
);
const
RE2
=
require
(
'
re2
'
);
...
@@ -18,8 +20,16 @@ try {
...
@@ -18,8 +20,16 @@ try {
}
}
export
function
regEx
(
pattern
:
string
|
RegExp
,
flags
?:
string
):
RegExp
{
export
function
regEx
(
pattern
:
string
|
RegExp
,
flags
?:
string
):
RegExp
{
const
key
=
`
${
pattern
.
toString
()}
:
${
flags
}
`
;
if
(
cache
.
has
(
key
))
{
return
cache
.
get
(
key
);
}
try
{
try
{
return
new
RegEx
(
pattern
,
flags
);
const
instance
=
new
RegEx
(
pattern
,
flags
);
cache
.
set
(
key
,
instance
);
return
instance
;
}
catch
(
err
)
{
}
catch
(
err
)
{
const
error
=
new
Error
(
CONFIG_VALIDATION
);
const
error
=
new
Error
(
CONFIG_VALIDATION
);
error
.
validationSource
=
pattern
.
toString
();
error
.
validationSource
=
pattern
.
toString
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment