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
f2444e57
Commit
f2444e57
authored
Nov 29, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis_server_protocol: move some code
parent
1b342f75
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
35 deletions
+34
-35
redis_command.cpp
src/brpc/redis_command.cpp
+34
-0
redis_command.h
src/brpc/redis_command.h
+0
-35
No files found.
src/brpc/redis_command.cpp
View file @
f2444e57
...
...
@@ -28,6 +28,40 @@ namespace brpc {
const
size_t
CTX_WIDTH
=
5
;
// Much faster than snprintf(..., "%lu", d);
inline
size_t
AppendDecimal
(
char
*
outbuf
,
unsigned
long
d
)
{
char
buf
[
24
];
// enough for decimal 64-bit integers
size_t
n
=
sizeof
(
buf
);
do
{
const
unsigned
long
q
=
d
/
10
;
buf
[
--
n
]
=
d
-
q
*
10
+
'0'
;
d
=
q
;
}
while
(
d
);
fast_memcpy
(
outbuf
,
buf
+
n
,
sizeof
(
buf
)
-
n
);
return
sizeof
(
buf
)
-
n
;
}
// This function is the hotspot of RedisCommandFormatV() when format is
// short or does not have many %. In a 100K-time call to formating of
// "GET key1", the time spent on RedisRequest.AddCommand() are ~700ns
// vs. ~400ns while using snprintf() vs. AppendDecimal() respectively.
inline
void
AppendHeader
(
std
::
string
&
buf
,
char
fc
,
unsigned
long
value
)
{
char
header
[
32
];
header
[
0
]
=
fc
;
size_t
len
=
AppendDecimal
(
header
+
1
,
value
);
header
[
len
+
1
]
=
'\r'
;
header
[
len
+
2
]
=
'\n'
;
buf
.
append
(
header
,
len
+
3
);
}
inline
void
AppendHeader
(
butil
::
IOBuf
&
buf
,
char
fc
,
unsigned
long
value
)
{
char
header
[
32
];
header
[
0
]
=
fc
;
size_t
len
=
AppendDecimal
(
header
+
1
,
value
);
header
[
len
+
1
]
=
'\r'
;
header
[
len
+
2
]
=
'\n'
;
buf
.
append
(
header
,
len
+
3
);
}
static
void
FlushComponent
(
std
::
string
*
out
,
std
::
string
*
compbuf
,
int
*
ncomp
)
{
AppendHeader
(
*
out
,
'$'
,
compbuf
->
size
());
out
->
append
(
*
compbuf
);
...
...
src/brpc/redis_command.h
View file @
f2444e57
...
...
@@ -40,41 +40,6 @@ butil::Status RedisCommandByComponents(butil::IOBuf* buf,
const
butil
::
StringPiece
*
components
,
size_t
num_components
);
// Much faster than snprintf(..., "%lu", d);
inline
size_t
AppendDecimal
(
char
*
outbuf
,
unsigned
long
d
)
{
char
buf
[
24
];
// enough for decimal 64-bit integers
size_t
n
=
sizeof
(
buf
);
do
{
const
unsigned
long
q
=
d
/
10
;
buf
[
--
n
]
=
d
-
q
*
10
+
'0'
;
d
=
q
;
}
while
(
d
);
fast_memcpy
(
outbuf
,
buf
+
n
,
sizeof
(
buf
)
-
n
);
return
sizeof
(
buf
)
-
n
;
}
// This function is the hotspot of RedisCommandFormatV() when format is
// short or does not have many %. In a 100K-time call to formating of
// "GET key1", the time spent on RedisRequest.AddCommand() are ~700ns
// vs. ~400ns while using snprintf() vs. AppendDecimal() respectively.
inline
void
AppendHeader
(
std
::
string
&
buf
,
char
fc
,
unsigned
long
value
)
{
char
header
[
32
];
header
[
0
]
=
fc
;
size_t
len
=
AppendDecimal
(
header
+
1
,
value
);
header
[
len
+
1
]
=
'\r'
;
header
[
len
+
2
]
=
'\n'
;
buf
.
append
(
header
,
len
+
3
);
}
inline
void
AppendHeader
(
butil
::
IOBuf
&
buf
,
char
fc
,
unsigned
long
value
)
{
char
header
[
32
];
header
[
0
]
=
fc
;
size_t
len
=
AppendDecimal
(
header
+
1
,
value
);
header
[
len
+
1
]
=
'\r'
;
header
[
len
+
2
]
=
'\n'
;
buf
.
append
(
header
,
len
+
3
);
}
}
// namespace brpc
...
...
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