Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
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
libzmq
Commits
c215235f
Commit
c215235f
authored
6 years ago
by
Simon Giesecke
Committed by
Simon Giesecke
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: redundant string operations in zmq::udp_engine_t::sockaddr_to_msg
Solution: reuse string lengths and use memcpy instead
parent
d451a952
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
udp_engine.cpp
src/udp_engine.cpp
+14
-7
No files found.
src/udp_engine.cpp
View file @
c215235f
...
...
@@ -319,19 +319,26 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg_, sockaddr_in *addr_)
const
char
*
const
name
=
inet_ntoa
(
addr_
->
sin_addr
);
char
port
[
6
];
const
int
port_len
=
sprintf
(
port
,
"%d"
,
static_cast
<
int
>
(
ntohs
(
addr_
->
sin_port
)));
zmq_assert
(
port_len
>
0
);
const
int
size
=
static_cast
<
int
>
(
strlen
(
name
))
+
static_cast
<
int
>
(
strlen
(
port
))
+
1
+
1
;
// Colon + NUL
L
const
size_t
name_len
=
strlen
(
name
);
const
int
size
=
static_cast
<
int
>
(
name_len
)
+
1
/* colon */
+
port_len
+
1
;
// terminating NU
L
const
int
rc
=
msg_
->
init_size
(
size
);
errno_assert
(
rc
==
0
);
msg_
->
set_flags
(
msg_t
::
more
);
char
*
address
=
static_cast
<
char
*>
(
msg_
->
data
());
strcpy
(
address
,
name
);
strcat
(
address
,
":"
);
strcat
(
address
,
port
);
// use memcpy instead of strcpy/strcat, since this is more efficient when
// we already know the lengths, which we calculated above
char
*
address
=
static_cast
<
char
*>
(
msg_
->
data
());
memcpy
(
address
,
name
,
name_len
);
address
+=
name_len
;
*
address
++
=
':'
;
memcpy
(
address
,
port
,
static_cast
<
size_t
>
(
port_len
));
address
+=
port_len
;
*
address
=
0
;
}
int
zmq
::
udp_engine_t
::
resolve_raw_address
(
char
*
name_
,
size_t
length_
)
...
...
This diff is collapsed.
Click to expand it.
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