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
a1fac159
Commit
a1fac159
authored
Mar 06, 2017
by
Milo Yip
Committed by
GitHub
Mar 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #872 from StilesCrisis/issue845_native_strlen
Use native strlen
parents
02de6989
c4e3d624
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
9 deletions
+70
-9
strfunc.h
include/rapidjson/internal/strfunc.h
+11
-0
prettywriter.h
include/rapidjson/prettywriter.h
+20
-4
writer.h
include/rapidjson/writer.h
+21
-4
CMakeLists.txt
test/unittest/CMakeLists.txt
+1
-1
valgrind.supp
test/valgrind.supp
+17
-0
No files found.
include/rapidjson/internal/strfunc.h
View file @
a1fac159
...
...
@@ -16,6 +16,7 @@
#define RAPIDJSON_INTERNAL_STRFUNC_H_
#include "../stream.h"
#include <cwchar>
RAPIDJSON_NAMESPACE_BEGIN
namespace
internal
{
...
...
@@ -34,6 +35,16 @@ inline SizeType StrLen(const Ch* s) {
return
SizeType
(
p
-
s
);
}
template
<>
inline
SizeType
StrLen
(
const
char
*
s
)
{
return
SizeType
(
std
::
strlen
(
s
));
}
template
<>
inline
SizeType
StrLen
(
const
wchar_t
*
s
)
{
return
SizeType
(
std
::
wcslen
(
s
));
}
//! Returns number of code points in a encoded string.
template
<
typename
Encoding
>
bool
CountStringCodePoint
(
const
typename
Encoding
::
Ch
*
s
,
SizeType
length
,
SizeType
*
outCount
)
{
...
...
include/rapidjson/prettywriter.h
View file @
a1fac159
...
...
@@ -107,7 +107,8 @@ public:
return
Base
::
WriteString
(
str
,
length
);
}
bool
String
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
RAPIDJSON_ASSERT
(
str
!=
0
);
(
void
)
copy
;
PrettyPrefix
(
kStringType
);
...
...
@@ -126,7 +127,8 @@ public:
return
Base
::
WriteStartObject
();
}
bool
Key
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
#if RAPIDJSON_HAS_STDSTRING
bool
Key
(
const
std
::
basic_string
<
Ch
>&
str
)
{
...
...
@@ -184,8 +186,22 @@ public:
//@{
//! Simpler but slower overload.
bool
String
(
const
Ch
*
str
)
{
return
String
(
str
,
internal
::
StrLen
(
str
));
}
bool
Key
(
const
Ch
*
str
)
{
return
Key
(
str
,
internal
::
StrLen
(
str
));
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
*
const
&
str
)
{
return
String
(
str
,
internal
::
StrLen
(
str
));
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
*
const
&
str
)
{
return
Key
(
str
,
internal
::
StrLen
(
str
));
}
//! The compiler can give us the length of quoted strings for free.
template
<
typename
T
,
size_t
N
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
(
&
str
)[
N
])
{
RAPIDJSON_ASSERT
(
str
[
N
-
1
]
==
'\0'
);
// you must pass in a null-terminated string (quoted constant strings are always null-terminated)
return
String
(
str
,
N
-
1
);
}
template
<
typename
T
,
size_t
N
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
(
&
str
)[
N
])
{
RAPIDJSON_ASSERT
(
str
[
N
-
1
]
==
'\0'
);
// you must pass in a null-terminated string (quoted constant strings are always null-terminated)
return
Key
(
str
,
N
-
1
);
}
//@}
...
...
include/rapidjson/writer.h
View file @
a1fac159
...
...
@@ -16,6 +16,7 @@
#define RAPIDJSON_WRITER_H_
#include "stream.h"
#include "internal/meta.h"
#include "internal/stack.h"
#include "internal/strfunc.h"
#include "internal/dtoa.h"
...
...
@@ -198,7 +199,8 @@ public:
return
EndValue
(
WriteString
(
str
,
length
));
}
bool
String
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
RAPIDJSON_ASSERT
(
str
!=
0
);
(
void
)
copy
;
Prefix
(
kStringType
);
...
...
@@ -217,7 +219,8 @@ public:
return
WriteStartObject
();
}
bool
Key
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
bool
EndObject
(
SizeType
memberCount
=
0
)
{
(
void
)
memberCount
;
...
...
@@ -247,8 +250,22 @@ public:
//@{
//! Simpler but slower overload.
bool
String
(
const
Ch
*
str
)
{
return
String
(
str
,
internal
::
StrLen
(
str
));
}
bool
Key
(
const
Ch
*
str
)
{
return
Key
(
str
,
internal
::
StrLen
(
str
));
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
*
const
&
str
)
{
return
String
(
str
,
internal
::
StrLen
(
str
));
}
template
<
typename
T
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
*
const
&
str
)
{
return
Key
(
str
,
internal
::
StrLen
(
str
));
}
//! The compiler can give us the length of quoted strings for free.
template
<
typename
T
,
size_t
N
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
String
(
const
T
(
&
str
)[
N
])
{
RAPIDJSON_ASSERT
(
str
[
N
-
1
]
==
'\0'
);
// you must pass in a null-terminated string (quoted constant strings are always null-terminated)
return
String
(
str
,
N
-
1
);
}
template
<
typename
T
,
size_t
N
>
RAPIDJSON_ENABLEIF_RETURN
((
internal
::
IsSame
<
Ch
,
T
>
),
(
bool
))
Key
(
const
T
(
&
str
)[
N
])
{
RAPIDJSON_ASSERT
(
str
[
N
-
1
]
==
'\0'
);
// you must pass in a null-terminated string (quoted constant strings are always null-terminated)
return
Key
(
str
,
N
-
1
);
}
//@}
...
...
test/unittest/CMakeLists.txt
View file @
a1fac159
...
...
@@ -79,7 +79,7 @@ add_test(NAME unittest
if
(
NOT MSVC
)
# Not running SIMD.* unit test cases for Valgrind
add_test
(
NAME valgrind_unittest
COMMAND valgrind --leak-check=full --error-exitcode=1
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/unittest --gtest_filter=-SIMD.*
COMMAND valgrind --
suppressions=
${
CMAKE_SOURCE_DIR
}
/test/valgrind.supp --
leak-check=full --error-exitcode=1
${
CMAKE_RUNTIME_OUTPUT_DIRECTORY
}
/unittest --gtest_filter=-SIMD.*
WORKING_DIRECTORY
${
CMAKE_SOURCE_DIR
}
/bin
)
if
(
CMAKE_BUILD_TYPE STREQUAL
"Debug"
)
...
...
test/valgrind.supp
0 → 100644
View file @
a1fac159
{
Suppress wcslen valgrind report 1
Memcheck:Cond
fun:__wcslen_sse2
}
{
Suppress wcslen valgrind report 2
Memcheck:Addr8
fun:__wcslen_sse2
}
{
Suppress wcslen valgrind report 3
Memcheck:Value8
fun:__wcslen_sse2
}
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