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
568d7595
Commit
568d7595
authored
Feb 15, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
experiment with user-defined allocator
parent
b1be1b45
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
16 deletions
+56
-16
src/json.hpp
src/json.hpp
+28
-8
src/json.hpp.re2c
src/json.hpp.re2c
+28
-8
No files found.
src/json.hpp
View file @
568d7595
...
@@ -59,7 +59,8 @@ template <
...
@@ -59,7 +59,8 @@ template <
class
StringType
=
std
::
string
,
class
StringType
=
std
::
string
,
class
BooleanType
=
bool
,
class
BooleanType
=
bool
,
class
NumberIntegerType
=
int64_t
,
class
NumberIntegerType
=
int64_t
,
class
NumberFloatType
=
double
class
NumberFloatType
=
double
,
template
<
typename
U
>
class
Allocator
=
std
::
allocator
>
>
class
basic_json
class
basic_json
{
{
...
@@ -199,7 +200,11 @@ class basic_json
...
@@ -199,7 +200,11 @@ class basic_json
case
(
value_t
:
:
string
)
:
case
(
value_t
:
:
string
)
:
{
{
m_value
.
string
=
new
string_t
(
""
);
Allocator
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
""
);
//m_value.string = new string_t("");
break
;
break
;
}
}
...
@@ -270,13 +275,21 @@ class basic_json
...
@@ -270,13 +275,21 @@ class basic_json
/// create a string (explicit)
/// create a string (explicit)
inline
basic_json
(
const
string_t
&
value
)
inline
basic_json
(
const
string_t
&
value
)
:
m_type
(
value_t
::
string
),
m_value
(
new
string_t
(
value
))
:
m_type
(
value_t
::
string
)
//, m_value(new string_t(value))
{}
{
Allocator
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
value
);
}
/// create a string (explicit)
/// create a string (explicit)
inline
basic_json
(
const
typename
string_t
::
value_type
*
value
)
inline
basic_json
(
const
typename
string_t
::
value_type
*
value
)
:
m_type
(
value_t
::
string
),
m_value
(
new
string_t
(
value
))
:
m_type
(
value_t
::
string
)
//, m_value(new string_t(value))
{}
{
Allocator
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
value
);
}
/// create a string (implicit)
/// create a string (implicit)
template
<
class
V
,
typename
template
<
class
V
,
typename
...
@@ -418,7 +431,10 @@ class basic_json
...
@@ -418,7 +431,10 @@ class basic_json
}
}
case
(
value_t
:
:
string
)
:
case
(
value_t
:
:
string
)
:
{
{
m_value
.
string
=
new
string_t
(
*
other
.
m_value
.
string
);
// m_value.string = new string_t(*other.m_value.string);
Allocator
<
string_t
>
alloc
;
m_value
.
string
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
string
,
*
other
.
m_value
.
string
);
break
;
break
;
}
}
case
(
value_t
:
:
boolean
)
:
case
(
value_t
:
:
boolean
)
:
...
@@ -483,8 +499,12 @@ class basic_json
...
@@ -483,8 +499,12 @@ class basic_json
case
(
value_t
:
:
string
)
:
case
(
value_t
:
:
string
)
:
{
{
delete
m_value
.
string
;
Allocator
<
string_t
>
alloc
;
alloc
.
deallocate
(
m_value
.
string
,
1
);
m_value
.
string
=
nullptr
;
m_value
.
string
=
nullptr
;
// delete m_value.string;
// m_value.string = nullptr;
break
;
break
;
}
}
...
...
src/json.hpp.re2c
View file @
568d7595
...
@@ -59,7 +59,8 @@ template <
...
@@ -59,7 +59,8 @@ template <
class StringType = std::string,
class StringType = std::string,
class BooleanType = bool,
class BooleanType = bool,
class NumberIntegerType = int64_t,
class NumberIntegerType = int64_t,
class NumberFloatType = double
class NumberFloatType = double,
template<typename U> class Allocator = std::allocator
>
>
class basic_json
class basic_json
{
{
...
@@ -199,7 +200,11 @@ class basic_json
...
@@ -199,7 +200,11 @@ class basic_json
case (value_t::string):
case (value_t::string):
{
{
m_value.string = new string_t("");
Allocator<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, "");
//m_value.string = new string_t("");
break;
break;
}
}
...
@@ -270,13 +275,21 @@ class basic_json
...
@@ -270,13 +275,21 @@ class basic_json
/// create a string (explicit)
/// create a string (explicit)
inline basic_json(const string_t& value)
inline basic_json(const string_t& value)
: m_type(value_t::string), m_value(new string_t(value))
: m_type(value_t::string)//, m_value(new string_t(value))
{}
{
Allocator<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, value);
}
/// create a string (explicit)
/// create a string (explicit)
inline basic_json(const typename string_t::value_type* value)
inline basic_json(const typename string_t::value_type* value)
: m_type(value_t::string), m_value(new string_t(value))
: m_type(value_t::string)//, m_value(new string_t(value))
{}
{
Allocator<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, value);
}
/// create a string (implicit)
/// create a string (implicit)
template <class V, typename
template <class V, typename
...
@@ -418,7 +431,10 @@ class basic_json
...
@@ -418,7 +431,10 @@ class basic_json
}
}
case (value_t::string):
case (value_t::string):
{
{
m_value.string = new string_t(*other.m_value.string);
// m_value.string = new string_t(*other.m_value.string);
Allocator<string_t> alloc;
m_value.string = alloc.allocate(1);
alloc.construct(m_value.string, *other.m_value.string);
break;
break;
}
}
case (value_t::boolean):
case (value_t::boolean):
...
@@ -483,8 +499,12 @@ class basic_json
...
@@ -483,8 +499,12 @@ class basic_json
case (value_t::string):
case (value_t::string):
{
{
delete m_value.string;
Allocator<string_t> alloc;
alloc.deallocate(m_value.string, 1);
m_value.string = nullptr;
m_value.string = nullptr;
// delete m_value.string;
// m_value.string = nullptr;
break;
break;
}
}
...
...
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