Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
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
capnproto
Commits
1bdce291
Commit
1bdce291
authored
Jun 12, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor parser code more.
parent
7001fc9d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
3 deletions
+16
-3
parse-test.c++
c++/src/kj/parse-test.c++
+0
-0
parse.h
c++/src/kj/parse.h
+0
-0
vector.h
c++/src/kj/vector.h
+16
-3
No files found.
c++/src/kj/parse-test.c++
View file @
1bdce291
This diff is collapsed.
Click to expand it.
c++/src/kj/parse.h
View file @
1bdce291
This diff is collapsed.
Click to expand it.
c++/src/kj/vector.h
View file @
1bdce291
...
...
@@ -36,6 +36,8 @@ class Vector {
// move constructor throws, the Vector is left in an inconsistent state. This is acceptable
// under KJ exception theory which assumes that exceptions leave things in inconsistent states.
// TODO(someday): Allow specifying a custom allocator.
public
:
inline
Vector
()
=
default
;
inline
explicit
Vector
(
size_t
capacity
)
:
builder
(
heapArrayBuilder
<
T
>
(
capacity
))
{}
...
...
@@ -59,6 +61,14 @@ public:
inline
T
&
front
()
{
return
builder
.
front
();
}
inline
T
&
back
()
{
return
builder
.
back
();
}
inline
Array
<
T
>
releaseAsArray
()
{
// TODO(perf): Avoid a copy/move by allowing Array<T> to point to incomplete space?
if
(
!
builder
.
isFull
())
{
setCapacity
(
size
());
}
return
builder
.
finish
();
}
template
<
typename
...
Params
>
inline
void
add
(
Params
&&
...
params
)
{
if
(
builder
.
isFull
())
grow
();
...
...
@@ -69,10 +79,13 @@ private:
ArrayBuilder
<
T
>
builder
;
void
grow
()
{
size_t
newSize
=
capacity
()
==
0
?
4
:
capacity
()
*
2
;
setCapacity
(
capacity
()
==
0
?
4
:
capacity
()
*
2
);
}
void
setCapacity
(
size_t
newSize
)
{
ArrayBuilder
<
T
>
newBuilder
=
heapArrayBuilder
<
T
>
(
newSize
);
for
(
T
&
element
:
builder
)
{
newBuilder
.
add
(
kj
::
mv
(
element
));
size_t
moveCount
=
kj
::
min
(
newSize
,
builder
.
size
());
for
(
size_t
i
=
0
;
i
<
moveCount
;
i
++
)
{
newBuilder
.
add
(
kj
::
mv
(
builder
[
i
]));
}
builder
=
kj
::
mv
(
newBuilder
);
}
...
...
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