Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
75bdb47d
Commit
75bdb47d
authored
Sep 20, 2017
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make parameter of ctor in QueryRemover be a pointer to avoid an extra copy
parent
557daeff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
21 deletions
+21
-21
uri.cpp
src/brpc/uri.cpp
+10
-10
uri.h
src/brpc/uri.h
+2
-2
brpc_uri_unittest.cpp
test/brpc_uri_unittest.cpp
+9
-9
No files found.
src/brpc/uri.cpp
View file @
75bdb47d
...
...
@@ -422,9 +422,9 @@ void QuerySplitter::split() {
_is_split
=
true
;
}
QueryRemover
::
QueryRemover
(
const
std
::
string
&
str
)
QueryRemover
::
QueryRemover
(
const
std
::
string
*
str
)
:
_query
(
str
)
,
_qs
(
_query
.
data
(),
_query
.
data
()
+
_query
.
size
())
,
_qs
(
str
->
data
(),
str
->
data
()
+
str
->
size
())
,
_iterated_len
(
0
)
,
_removed_current_key_value
(
false
)
,
_ever_removed
(
false
)
{
...
...
@@ -463,9 +463,9 @@ void QueryRemover::remove_current_key_and_value() {
_removed_current_key_value
=
true
;
if
(
!
_ever_removed
)
{
_ever_removed
=
true
;
size_t
offset
=
key
().
data
()
-
_query
.
data
();
size_t
len
=
offset
-
((
offset
>
0
&&
_query
[
offset
-
1
]
==
'&'
)
?
1
:
0
);
_modified_query
.
append
(
_query
.
data
(),
len
);
size_t
offset
=
key
().
data
()
-
_query
->
data
();
size_t
len
=
offset
-
((
offset
>
0
&&
(
*
_query
)
[
offset
-
1
]
==
'&'
)
?
1
:
0
);
_modified_query
.
append
(
_query
->
data
(),
len
);
_iterated_len
+=
len
;
}
return
;
...
...
@@ -473,24 +473,24 @@ void QueryRemover::remove_current_key_and_value() {
std
::
string
QueryRemover
::
modified_query
()
{
if
(
!
_ever_removed
)
{
return
_query
;
return
*
_query
;
}
size_t
offset
=
key
().
data
()
-
_query
.
data
();
size_t
offset
=
key
().
data
()
-
_query
->
data
();
// find out where the remaining string starts
if
(
_removed_current_key_value
)
{
size_t
size
=
key_and_value
().
length
();
while
(
offset
+
size
<
_query
.
size
()
&&
_query
[
offset
+
size
]
==
'&'
)
{
while
(
offset
+
size
<
_query
->
size
()
&&
(
*
_query
)
[
offset
+
size
]
==
'&'
)
{
// ingore unnecessary '&'
size
+=
1
;
}
offset
+=
size
;
}
_modified_query
.
resize
(
_iterated_len
);
if
(
offset
<
_query
.
size
())
{
if
(
offset
<
_query
->
size
())
{
if
(
!
_modified_query
.
empty
())
{
_modified_query
.
push_back
(
'&'
);
}
_modified_query
.
append
(
_query
,
offset
,
std
::
string
::
npos
);
_modified_query
.
append
(
*
_query
,
offset
,
std
::
string
::
npos
);
}
return
_modified_query
;
}
...
...
src/brpc/uri.h
View file @
75bdb47d
...
...
@@ -265,7 +265,7 @@ private:
// query.
class
QueryRemover
{
public
:
QueryRemover
(
const
std
::
string
&
str
);
QueryRemover
(
const
std
::
string
*
str
);
const
butil
::
StringPiece
&
key
()
{
return
_qs
.
key
();}
const
butil
::
StringPiece
&
value
()
{
return
_qs
.
value
();
}
...
...
@@ -285,7 +285,7 @@ public:
std
::
string
modified_query
();
private
:
const
std
::
string
_query
;
const
std
::
string
*
_query
;
QuerySplitter
_qs
;
std
::
string
_modified_query
;
size_t
_iterated_len
;
...
...
test/brpc_uri_unittest.cpp
View file @
75bdb47d
...
...
@@ -329,7 +329,7 @@ TEST(URITest, copy_and_assign) {
TEST
(
URITest
,
query_remover_sanity
)
{
std
::
string
query
=
"key1=value1&key2=value2&key3=value3"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
ASSERT_EQ
(
qr
.
key
(),
"key1"
);
ASSERT_EQ
(
qr
.
value
(),
"value1"
);
...
...
@@ -345,7 +345,7 @@ TEST(URITest, query_remover_sanity) {
TEST
(
URITest
,
query_remover_remove_current_key_and_value
)
{
std
::
string
query
=
"key1=value1&key2=value2&key3=value3"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
qr
.
remove_current_key_and_value
();
ASSERT_EQ
(
qr
.
modified_query
(),
"key2=value2&key3=value3"
);
...
...
@@ -366,7 +366,7 @@ TEST(URITest, query_remover_remove_current_key_and_value) {
TEST
(
URITest
,
query_remover_random_remove
)
{
std
::
string
query
=
"key1=value1&key2=value2&key3=value3&key4=value4"
"&key5=value5&key6=value6"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
++
qr
;
++
qr
;
...
...
@@ -381,7 +381,7 @@ TEST(URITest, query_remover_random_remove) {
TEST
(
URITest
,
query_remover_onekey_remove
)
{
std
::
string
query
=
"key1=value1&key2=value2&key3=value3&key4=value4"
"&key5=value5&key6=value6"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
++
qr
;
++
qr
;
...
...
@@ -399,7 +399,7 @@ TEST(URITest, query_remover_onekey_remove) {
TEST
(
URITest
,
query_remover_consecutive_ampersand
)
{
std
::
string
query
=
"key1=value1&&&key2=value2&key3=value3&&"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
qr
.
remove_current_key_and_value
();
ASSERT_EQ
(
qr
.
modified_query
(),
"key2=value2&key3=value3&&"
);
...
...
@@ -415,7 +415,7 @@ TEST(URITest, query_remover_consecutive_ampersand) {
TEST
(
URITest
,
query_remover_only_equality
)
{
std
::
string
query
=
"key1=&&key2&=&key3=value3"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
ASSERT_EQ
(
qr
.
key
(),
"key1"
);
ASSERT_EQ
(
qr
.
value
(),
""
);
...
...
@@ -436,7 +436,7 @@ TEST(URITest, query_remover_only_equality) {
TEST
(
URITest
,
query_remover_only_one_key
)
{
std
::
string
query
=
"key1"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
ASSERT_EQ
(
qr
.
key
(),
"key1"
);
ASSERT_EQ
(
qr
.
value
(),
""
);
...
...
@@ -448,7 +448,7 @@ TEST(URITest, query_remover_only_one_key) {
TEST
(
URITest
,
query_remover_no_modify
)
{
std
::
string
query
=
"key1=value1&key2=value2&key3=value3"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
ASSERT_EQ
(
qr
.
key
(),
"key1"
);
ASSERT_EQ
(
qr
.
value
(),
"value1"
);
...
...
@@ -461,7 +461,7 @@ TEST(URITest, query_remover_no_modify) {
TEST
(
URITest
,
query_remover_key_value_not_changed_after_modified_query
)
{
std
::
string
query
=
"key1=value1&key2=value2&key3=value3"
;
brpc
::
QueryRemover
qr
(
query
);
brpc
::
QueryRemover
qr
(
&
query
);
ASSERT_TRUE
(
qr
);
++
qr
;
ASSERT_EQ
(
qr
.
key
(),
"key2"
);
...
...
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