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
e6c97c5e
Commit
e6c97c5e
authored
Jan 03, 2012
by
Staffan Gimåker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce memory usage of mtrie.
Signed-off-by:
Staffan Gimåker
<
staffan@spotify.com
>
parent
7e8a839a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
11 deletions
+30
-11
mtrie.cpp
src/mtrie.cpp
+29
-10
mtrie.hpp
src/mtrie.hpp
+1
-1
No files found.
src/mtrie.cpp
View file @
e6c97c5e
...
...
@@ -34,6 +34,7 @@
#include "mtrie.hpp"
zmq
::
mtrie_t
::
mtrie_t
()
:
pipes
(
0
),
min
(
0
),
count
(
0
),
live_nodes
(
0
)
...
...
@@ -42,6 +43,11 @@ zmq::mtrie_t::mtrie_t () :
zmq
::
mtrie_t
::~
mtrie_t
()
{
if
(
pipes
)
{
delete
pipes
;
pipes
=
0
;
}
if
(
count
==
1
)
{
zmq_assert
(
next
.
node
);
delete
next
.
node
;
...
...
@@ -65,8 +71,10 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
{
// We are at the node corresponding to the prefix. We are done.
if
(
!
size_
)
{
bool
result
=
pipes
.
empty
();
pipes
.
insert
(
pipe_
);
bool
result
=
!
pipes
;
if
(
!
pipes
)
pipes
=
new
pipes_t
;
pipes
->
insert
(
pipe_
);
return
result
;
}
...
...
@@ -154,8 +162,11 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
void
*
arg_
)
{
// Remove the subscription from this node.
if
(
pipes
.
erase
(
pipe_
)
&&
pipes
.
empty
())
if
(
pipes
&&
pipes
->
erase
(
pipe_
)
&&
pipes
->
empty
())
{
func_
(
*
buff_
,
buffsize_
,
arg_
);
delete
pipes
;
pipes
=
0
;
}
// Adjust the buffer.
if
(
buffsize_
>=
maxbuffsize_
)
{
...
...
@@ -207,9 +218,15 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
pipe_t
*
pipe_
)
{
if
(
!
size_
)
{
pipes_t
::
size_type
erased
=
pipes
.
erase
(
pipe_
);
zmq_assert
(
erased
==
1
);
return
pipes
.
empty
();
if
(
pipes
)
{
pipes_t
::
size_type
erased
=
pipes
->
erase
(
pipe_
);
zmq_assert
(
erased
==
1
);
if
(
pipes
->
empty
())
{
delete
pipes
;
pipes
=
0
;
}
}
return
!
pipes
;
}
unsigned
char
c
=
*
prefix_
;
...
...
@@ -245,9 +262,11 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
while
(
true
)
{
// Signal the pipes attached to this node.
for
(
pipes_t
::
iterator
it
=
current
->
pipes
.
begin
();
it
!=
current
->
pipes
.
end
();
++
it
)
func_
(
*
it
,
arg_
);
if
(
current
->
pipes
)
{
for
(
pipes_t
::
iterator
it
=
current
->
pipes
->
begin
();
it
!=
current
->
pipes
->
end
();
++
it
)
func_
(
*
it
,
arg_
);
}
// If we are at the end of the message, there's nothing more to match.
if
(
!
size_
)
...
...
@@ -281,5 +300,5 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
bool
zmq
::
mtrie_t
::
is_redundant
()
const
{
return
pipes
.
empty
()
&&
live_nodes
==
0
;
return
!
pipes
&&
live_nodes
==
0
;
}
src/mtrie.hpp
View file @
e6c97c5e
...
...
@@ -73,7 +73,7 @@ namespace zmq
bool
is_redundant
()
const
;
typedef
std
::
set
<
zmq
::
pipe_t
*>
pipes_t
;
pipes_t
pipes
;
pipes_t
*
pipes
;
unsigned
char
min
;
unsigned
short
count
;
...
...
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