Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
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
rapidjson
Commits
01126def
Commit
01126def
authored
Jul 26, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Stack::Push() force inline in normal path
parent
e9597255
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
stack.h
include/rapidjson/internal/stack.h
+19
-12
No files found.
include/rapidjson/internal/stack.h
View file @
01126def
...
...
@@ -28,20 +28,14 @@ public:
void
Clear
()
{
/*stack_top_ = 0;*/
stack_top_
=
stack_
;
}
// Optimization note: try to minimize the size of this function for force inline.
// Expansion is run very infrequently, so it is moved to another (probably non-inline) function.
template
<
typename
T
>
T
*
Push
(
size_t
count
=
1
)
{
RAPIDJSON_FORCEINLINE
T
*
Push
(
size_t
count
=
1
)
{
// Expand the stack if needed
if
(
stack_top_
+
sizeof
(
T
)
*
count
>=
stack_end_
)
{
size_t
new_capacity
=
stack_capacity_
*
2
;
size_t
size
=
GetSize
();
size_t
new_size
=
GetSize
()
+
sizeof
(
T
)
*
count
;
if
(
new_capacity
<
new_size
)
new_capacity
=
new_size
;
stack_
=
(
char
*
)
allocator_
->
Realloc
(
stack_
,
stack_capacity_
,
new_capacity
);
stack_capacity_
=
new_capacity
;
stack_top_
=
stack_
+
size
;
stack_end_
=
stack_
+
stack_capacity_
;
}
if
(
stack_top_
+
sizeof
(
T
)
*
count
>=
stack_end_
)
Expand
<
T
>
(
count
);
T
*
ret
=
reinterpret_cast
<
T
*>
(
stack_top_
);
stack_top_
+=
sizeof
(
T
)
*
count
;
return
ret
;
...
...
@@ -69,6 +63,19 @@ public:
size_t
GetCapacity
()
const
{
return
stack_capacity_
;
}
private
:
template
<
typename
T
>
void
Expand
(
size_t
count
)
{
size_t
new_capacity
=
stack_capacity_
*
2
;
size_t
size
=
GetSize
();
size_t
new_size
=
GetSize
()
+
sizeof
(
T
)
*
count
;
if
(
new_capacity
<
new_size
)
new_capacity
=
new_size
;
stack_
=
(
char
*
)
allocator_
->
Realloc
(
stack_
,
stack_capacity_
,
new_capacity
);
stack_capacity_
=
new_capacity
;
stack_top_
=
stack_
+
size
;
stack_end_
=
stack_
+
stack_capacity_
;
}
// Prohibit copy constructor & assignment operator.
Stack
(
const
Stack
&
);
Stack
&
operator
=
(
const
Stack
&
);
...
...
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