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
9c567060
Commit
9c567060
authored
Aug 14, 2018
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace JsonCodec STL maps with KJ maps.
parent
842e0d59
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
6 deletions
+29
-6
json.c++
c++/src/capnp/compat/json.c++
+0
-0
generated-header-support.h
c++/src/capnp/generated-header-support.h
+1
-0
schema.c++
c++/src/capnp/schema.c++
+11
-5
schema.h
c++/src/capnp/schema.h
+17
-1
No files found.
c++/src/capnp/compat/json.c++
View file @
9c567060
This diff is collapsed.
Click to expand it.
c++/src/capnp/generated-header-support.h
View file @
9c567060
...
...
@@ -35,6 +35,7 @@
#include "any.h"
#include <kj/string.h>
#include <kj/string-tree.h>
#include <kj/hash.h>
namespace
capnp
{
...
...
c++/src/capnp/schema.c++
View file @
9c567060
...
...
@@ -25,6 +25,12 @@
namespace
capnp
{
namespace
schema
{
uint
KJ_HASHCODE
(
Type
::
Which
w
)
{
return
kj
::
hashCode
(
static_cast
<
uint16_t
>
(
w
));
}
// TODO(cleanup): Cap'n Proto does not declare stringifiers nor hashers for `Which` enums, unlike
// all other enums. Fix that and remove this.
}
namespace
_
{
// private
// Null schemas generated using the below schema file with:
...
...
@@ -868,7 +874,7 @@ bool Type::operator==(const Type& other) const {
KJ_UNREACHABLE
;
}
size_
t
Type
::
hashCode
()
const
{
uin
t
Type
::
hashCode
()
const
{
switch
(
baseType
)
{
case
schema
:
:
Type
::
VOID
:
case
schema
:
:
Type
::
BOOL
:
...
...
@@ -884,12 +890,12 @@ size_t Type::hashCode() const {
case
schema
:
:
Type
::
FLOAT64
:
case
schema
:
:
Type
::
TEXT
:
case
schema
:
:
Type
::
DATA
:
return
(
static_cast
<
size_t
>
(
baseType
)
<<
3
)
+
listDepth
;
return
kj
::
hashCode
(
baseType
,
listDepth
)
;
case
schema
:
:
Type
::
STRUCT
:
case
schema
:
:
Type
::
ENUM
:
case
schema
:
:
Type
::
INTERFACE
:
return
reinterpret_cast
<
size_t
>
(
schema
)
+
listDepth
;
return
kj
::
hashCode
(
schema
,
listDepth
)
;
case
schema
:
:
Type
::
LIST
:
KJ_UNREACHABLE
;
...
...
@@ -897,9 +903,9 @@ size_t Type::hashCode() const {
case
schema
:
:
Type
::
ANY_POINTER
:
{
// Trying to comply with strict aliasing rules. Hopefully the compiler realizes that
// both branches compile to the same instructions and can optimize it away.
size
_t
val
=
scopeId
!=
0
||
isImplicitParam
?
uint16
_t
val
=
scopeId
!=
0
||
isImplicitParam
?
paramIndex
:
static_cast
<
uint16_t
>
(
anyPointerKind
);
return
(
val
<<
1
|
isImplicitParam
)
^
scopeId
;
return
kj
::
hashCode
(
val
,
isImplicitParam
,
scopeId
)
;
}
}
...
...
c++/src/capnp/schema.h
View file @
9c567060
...
...
@@ -30,6 +30,7 @@
#endif
#include <capnp/schema.capnp.h>
#include <kj/hash.h>
#include <kj/windows-sanity.h> // work-around macro conflict with `VOID`
namespace
capnp
{
...
...
@@ -129,6 +130,8 @@ public:
// you want to check if two Schemas represent the same type (but possibly different versions of
// it), compare their IDs instead.
inline
uint
hashCode
()
const
{
return
kj
::
hashCode
(
raw
);
}
template
<
typename
T
>
void
requireUsableAs
()
const
;
// Throws an exception if a value with this Schema cannot safely be cast to a native value of
...
...
@@ -302,6 +305,7 @@ public:
inline
bool
operator
==
(
const
Field
&
other
)
const
;
inline
bool
operator
!=
(
const
Field
&
other
)
const
{
return
!
(
*
this
==
other
);
}
inline
uint
hashCode
()
const
;
private
:
StructSchema
parent
;
...
...
@@ -400,6 +404,7 @@ public:
inline
bool
operator
==
(
const
Enumerant
&
other
)
const
;
inline
bool
operator
!=
(
const
Enumerant
&
other
)
const
{
return
!
(
*
this
==
other
);
}
inline
uint
hashCode
()
const
;
private
:
EnumSchema
parent
;
...
...
@@ -492,6 +497,7 @@ public:
inline
bool
operator
==
(
const
Method
&
other
)
const
;
inline
bool
operator
!=
(
const
Method
&
other
)
const
{
return
!
(
*
this
==
other
);
}
inline
uint
hashCode
()
const
;
private
:
InterfaceSchema
parent
;
...
...
@@ -644,7 +650,7 @@ public:
bool
operator
==
(
const
Type
&
other
)
const
;
inline
bool
operator
!=
(
const
Type
&
other
)
const
{
return
!
(
*
this
==
other
);
}
size_
t
hashCode
()
const
;
uin
t
hashCode
()
const
;
inline
Type
wrapInList
(
uint
depth
=
1
)
const
;
// Return the Type formed by wrapping this type in List() `depth` times.
...
...
@@ -796,6 +802,16 @@ inline bool InterfaceSchema::Method::operator==(const Method& other) const {
return
parent
==
other
.
parent
&&
ordinal
==
other
.
ordinal
;
}
inline
uint
StructSchema
::
Field
::
hashCode
()
const
{
return
kj
::
hashCode
(
parent
,
index
);
}
inline
uint
EnumSchema
::
Enumerant
::
hashCode
()
const
{
return
kj
::
hashCode
(
parent
,
index
);
}
inline
uint
InterfaceSchema
::
Method
::
hashCode
()
const
{
return
kj
::
hashCode
(
parent
,
index
);
}
inline
ListSchema
ListSchema
::
of
(
StructSchema
elementType
)
{
return
ListSchema
(
Type
(
elementType
));
}
...
...
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