Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-re2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-re2
Commits
025f5654
Commit
025f5654
authored
Mar 16, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compute the length of the subject string only once in match()
parent
54295ce5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
11 deletions
+13
-11
vmod_re2.c
src/vmod_re2.c
+4
-3
vre2.cpp
src/vre2/vre2.cpp
+6
-6
vre2.h
src/vre2/vre2.h
+3
-2
No files found.
src/vmod_re2.c
View file @
025f5654
...
...
@@ -151,7 +151,7 @@ VCL_BOOL
vmod_regex_match
(
const
struct
vrt_ctx
*
ctx
,
struct
vmod_re2_regex
*
re
,
VCL_STRING
subject
)
{
int
match
=
0
,
ngroups
=
0
;
int
match
=
0
,
ngroups
=
0
,
len
;
const
char
*
err
;
char
*
text
=
(
void
*
)
subject
;
void
*
group
=
NULL
;
...
...
@@ -165,9 +165,10 @@ vmod_regex_match(const struct vrt_ctx *ctx, struct vmod_re2_regex *re,
AZ
(
pthread_setspecific
(
re
->
matchk
,
match_failed
));
len
=
strlen
(
subject
);
if
(
!
re
->
never_capture
)
{
ngroups
=
re
->
ngroups
+
1
;
if
((
text
=
WS_Copy
(
ctx
->
ws
,
subject
,
-
1
))
==
NULL
)
{
if
((
text
=
WS_Copy
(
ctx
->
ws
,
subject
,
len
+
1
))
==
NULL
)
{
VERR
(
ctx
,
ERR_PREFIX
"insufficient workspace to copy "
"subject"
,
re
->
vcl_name
,
subject
);
return
0
;
...
...
@@ -181,7 +182,7 @@ vmod_regex_match(const struct vrt_ctx *ctx, struct vmod_re2_regex *re,
}
}
if
((
err
=
vre2_match
(
re
->
vre2
,
text
,
&
match
,
ngroups
,
group
))
if
((
err
=
vre2_match
(
re
->
vre2
,
text
,
len
,
&
match
,
ngroups
,
group
))
!=
NULL
)
{
VERR
(
ctx
,
ERR_PREFIX
"%s"
,
re
->
vcl_name
,
subject
,
err
);
WS_Reset
(
ctx
->
ws
,
text
);
...
...
src/vre2/vre2.cpp
View file @
025f5654
...
...
@@ -56,10 +56,10 @@ vre2::~vre2() {
}
inline
bool
vre2
::
match
(
const
char
*
subject
,
const
int
ngroups
,
StringPiece
*
groups
)
const
vre2
::
match
(
const
char
*
subject
,
const
size_t
len
,
const
int
ngroups
,
StringPiece
*
groups
)
const
{
return
re_
->
Match
(
subject
,
0
,
strlen
(
subject
),
RE2
::
UNANCHORED
,
groups
,
ngroups
);
return
re_
->
Match
(
subject
,
0
,
len
,
RE2
::
UNANCHORED
,
groups
,
ngroups
);
}
inline
const
int
...
...
@@ -106,12 +106,12 @@ vre2_matchsz(void)
}
const
char
*
vre2_match
(
vre2
*
vre2
,
const
char
*
const
subject
,
int
*
const
match
,
const
int
ngroups
,
void
*
const
group
)
vre2_match
(
vre2
*
vre2
,
const
char
*
const
subject
,
const
size_t
len
,
int
*
const
match
,
const
int
ngroups
,
void
*
const
group
)
{
try
{
StringPiece
*
g
=
reinterpret_cast
<
StringPiece
*>
(
group
);
*
match
=
vre2
->
match
(
subject
,
ngroups
,
g
);
*
match
=
vre2
->
match
(
subject
,
len
,
ngroups
,
g
);
return
NULL
;
}
CATCHALL
...
...
src/vre2/vre2.h
View file @
025f5654
...
...
@@ -43,7 +43,8 @@ private:
public
:
vre2
(
const
char
*
pattern
,
RE2
::
Options
*
const
opt
);
virtual
~
vre2
();
bool
match
(
const
char
*
subject
,
int
ngroups
,
StringPiece
*
groups
)
const
;
bool
match
(
const
char
*
subject
,
size_t
len
,
int
ngroups
,
StringPiece
*
groups
)
const
;
const
int
ngroups
()
const
;
};
#else
...
...
@@ -65,7 +66,7 @@ extern "C" {
const
size_t
vre2_matchsz
(
void
);
const
char
*
vre2_ngroups
(
vre2
*
vre2
,
int
*
const
ngroups
);
const
char
*
vre2_match
(
vre2
*
vre2
,
const
char
*
const
subject
,
int
*
const
match
,
int
ngroups
,
size_t
len
,
int
*
const
match
,
int
ngroups
,
void
*
const
group
);
const
char
*
vre2_capture
(
void
*
group
,
int
refnum
,
const
char
**
const
capture
,
int
*
const
len
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment