Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
4fbff7d1
Commit
4fbff7d1
authored
Apr 26, 2015
by
Florian Weber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify value_t::operator< by using a lookup-table
parent
f5e95522
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
138 deletions
+22
-138
src/json.hpp
src/json.hpp
+11
-69
src/json.hpp.re2c
src/json.hpp.re2c
+11
-69
No files found.
src/json.hpp
View file @
4fbff7d1
...
...
@@ -11,6 +11,7 @@
#define NLOHMANN_JSON_HPP
#include <algorithm>
#include <array>
#include <ciso646>
#include <cmath>
#include <cstdio>
...
...
@@ -202,76 +203,17 @@ class basic_json
*/
friend
bool
operator
<
(
const
value_t
lhs
,
const
value_t
rhs
)
{
// no type is smaller than itself
if
(
lhs
==
rhs
)
{
return
false
;
}
switch
(
lhs
)
{
case
(
value_t
:
:
null
)
:
{
// nulls are smaller than all other types
return
true
;
}
case
(
value_t
:
:
boolean
)
:
{
// only nulls are smaller than booleans
return
(
rhs
!=
value_t
::
null
);
}
case
(
value_t
:
:
number_float
)
:
case
(
value_t
:
:
number_integer
)
:
{
switch
(
rhs
)
{
// numbers are smaller than objects, arrays, and string
case
(
value_t
:
:
object
)
:
case
(
value_t
:
:
array
)
:
case
(
value_t
:
:
string
)
:
{
return
true
;
}
default:
{
return
false
;
}
}
}
case
(
value_t
:
:
object
)
:
{
switch
(
rhs
)
{
// objects are smaller than arrays and string
case
(
value_t
:
:
array
)
:
case
(
value_t
:
:
string
)
:
{
return
true
;
}
default:
{
return
false
;
}
}
}
case
(
value_t
:
:
array
)
:
{
// arrays are smaller than strings
return
(
rhs
==
value_t
::
string
);
}
default:
{
// a string is not smaller than any other types
return
false
;
}
std
::
array
<
uint8_t
,
7
>
order
=
{{
0
,
// null
3
,
// object
4
,
// array
5
,
// string
1
,
// boolean
2
,
// integer
2
// float
}
};
return
order
[
static_cast
<
std
::
size_t
>
(
lhs
)]
<
order
[
static_cast
<
std
::
size_t
>
(
rhs
)];
}
...
...
src/json.hpp.re2c
View file @
4fbff7d1
...
...
@@ -11,6 +11,7 @@
#define NLOHMANN_JSON_HPP
#include <algorithm>
#include <array>
#include <ciso646>
#include <cmath>
#include <cstdio>
...
...
@@ -202,76 +203,17 @@ class basic_json
*/
friend bool operator<(const value_t lhs, const value_t rhs)
{
// no type is smaller than itself
if (lhs == rhs)
{
return false;
}
switch (lhs)
{
case (value_t::null):
{
// nulls are smaller than all other types
return true;
}
case (value_t::boolean):
{
// only nulls are smaller than booleans
return (rhs != value_t::null);
}
case (value_t::number_float):
case (value_t::number_integer):
{
switch (rhs)
{
// numbers are smaller than objects, arrays, and string
case (value_t::object):
case (value_t::array):
case (value_t::string):
{
return true;
}
default:
{
return false;
}
}
}
case (value_t::object):
{
switch (rhs)
{
// objects are smaller than arrays and string
case (value_t::array):
case (value_t::string):
{
return true;
}
default:
{
return false;
}
}
}
case (value_t::array):
{
// arrays are smaller than strings
return (rhs == value_t::string);
}
default:
{
// a string is not smaller than any other types
return false;
}
std::array<uint8_t, 7> order = {{
0, // null
3, // object
4, // array
5, // string
1, // boolean
2, // integer
2 // float
}
};
return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
}
...
...
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