Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
7ff89e52
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7ff89e52
编写于
8月 31, 2020
作者:
石
石晓伟
提交者:
GitHub
8月 31, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix likely macros, test=develop (#4208)
上级
31572a49
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
26 deletion
+23
-26
lite/utils/charconv.h
lite/utils/charconv.h
+23
-26
未找到文件。
lite/utils/charconv.h
浏览文件 @
7ff89e52
...
...
@@ -18,15 +18,8 @@
#include <algorithm>
#include <climits>
#include <limits>
#include <system_error> // NOLINT
#ifndef likely
#define likely(x) __builtin_expect((x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect((x), 0)
#endif
#include <system_error> // NOLINT
#include "lite/utils/variant.h" // for likely
namespace
paddle
{
namespace
lite
{
...
...
@@ -45,12 +38,15 @@ struct from_chars_result {
};
/*
* Reference:
* https://github.com/VerizonDigital/json_parser
*
* Most C++ environments use ASCII as the development character
* set. Array `kAsciiToInt` is the look-up table implementation
* of the following functions:
*
* static inline uint8_t get_char_val(char c) {
* if (
likely
(c >= '0' && c <= '9'))
* if (
LIKELY
(c >= '0' && c <= '9'))
* return c - '0';
* if (c >= 'A' && c <= 'Z')
* return 10 + (c - 'A');
...
...
@@ -104,7 +100,8 @@ constexpr uint8_t kAsciiToInt[256] = {
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
,
UCHAR_MAX
};
/* function: aton_unsigned
/*
* function: aton_unsigned
* brief: Convert a string constant to an unsigned integer.
* parameters:
* str(const char*): input string constant.
...
...
@@ -122,30 +119,30 @@ from_chars_result aton_unsigned(const char* str,
from_chars_result
result
;
result
.
ptr
=
str
;
if
(
unlikely
(
!
str
||
len
<=
0
))
{
if
(
UNLIKELY
(
!
str
||
len
<=
0
))
{
result
.
ec
=
std
::
errc
::
invalid_argument
;
return
result
;
}
uint64_t
val
=
0
;
if
(
unlikely
(
*
str
==
'-'
))
{
if
(
UNLIKELY
(
*
str
==
'-'
))
{
result
.
ec
=
std
::
errc
::
result_out_of_range
;
return
result
;
}
if
(
unlikely
(
*
str
==
'+'
))
{
if
(
UNLIKELY
(
*
str
==
'+'
))
{
++
str
;
--
len
;
}
int
i
=
0
;
for
(;
i
<
len
;
++
i
)
{
uint8_t
cv
=
kAsciiToInt
[
reinterpret_cast
<
const
uint8_t
&>
(
str
[
i
])];
if
(
unlikely
(
cv
>=
base
))
{
if
(
UNLIKELY
(
cv
>=
base
))
{
value
=
static_cast
<
T
>
(
val
);
result
.
ptr
=
str
+
i
;
return
result
;
}
// Handling integer values that may exceed the range represented by the
// basic type.
if
(
unlikely
(
i
>
std
::
numeric_limits
<
uint32_t
>::
digits10
+
1
)
&&
if
(
UNLIKELY
(
i
>
std
::
numeric_limits
<
uint32_t
>::
digits10
+
1
)
&&
i
==
std
::
numeric_limits
<
uint64_t
>::
digits10
)
{
uint64_t
mx
=
static_cast
<
uint64_t
>
(
std
::
numeric_limits
<
T
>::
max
());
if
(
val
>
mx
/
10
||
mx
-
(
val
*
base
)
<
cv
)
{
...
...
@@ -154,12 +151,12 @@ from_chars_result aton_unsigned(const char* str,
return
result
;
}
}
if
(
likely
(
i
!=
10
))
{
if
(
LIKELY
(
i
!=
10
))
{
val
*=
base
;
}
val
+=
cv
;
}
if
(
unlikely
(
i
>
std
::
numeric_limits
<
T
>::
digits10
+
1
||
if
(
UNLIKELY
(
i
>
std
::
numeric_limits
<
T
>::
digits10
+
1
||
(
i
>
std
::
numeric_limits
<
T
>::
digits10
&&
val
>
static_cast
<
uint64_t
>
(
std
::
numeric_limits
<
T
>::
max
()))))
{
value
=
static_cast
<
T
>
(
std
::
numeric_limits
<
T
>::
max
());
...
...
@@ -188,7 +185,7 @@ from_chars_result aton_signed(const char* str,
from_chars_result
result
;
result
.
ptr
=
str
;
if
(
unlikely
(
!
str
||
len
<=
0
))
{
if
(
UNLIKELY
(
!
str
||
len
<=
0
))
{
result
.
ec
=
std
::
errc
::
invalid_argument
;
return
result
;
}
...
...
@@ -201,18 +198,18 @@ from_chars_result aton_signed(const char* str,
int
i
=
0
;
for
(;
i
<
len
;
++
i
)
{
uint8_t
cv
=
kAsciiToInt
[
reinterpret_cast
<
const
uint8_t
&>
(
str
[
i
])];
if
(
unlikely
(
cv
>=
base
))
{
if
(
UNLIKELY
(
cv
>=
base
))
{
value
=
static_cast
<
T
>
(
val
);
result
.
ptr
=
str
+
i
;
return
result
;
}
if
(
likely
(
i
!=
0
))
{
if
(
LIKELY
(
i
!=
0
))
{
val
*=
base
;
}
val
+=
cv
;
}
if
(
likely
(
!
negative
))
{
if
(
unlikely
(
i
>
std
::
numeric_limits
<
T
>::
digits10
+
1
||
if
(
LIKELY
(
!
negative
))
{
if
(
UNLIKELY
(
i
>
std
::
numeric_limits
<
T
>::
digits10
+
1
||
(
i
>
std
::
numeric_limits
<
T
>::
digits10
&&
val
>
static_cast
<
int64_t
>
(
std
::
numeric_limits
<
T
>::
max
()))))
{
value
=
static_cast
<
T
>
(
std
::
numeric_limits
<
T
>::
max
());
...
...
@@ -251,7 +248,7 @@ from_chars_result aton_float(const char* str, int len, T& value) { // NOLINT
result
.
ptr
=
str
;
const
uint8_t
base
=
10
;
if
(
unlikely
(
!
str
||
len
<=
0
))
{
if
(
UNLIKELY
(
!
str
||
len
<=
0
))
{
result
.
ec
=
std
::
errc
::
invalid_argument
;
return
result
;
}
...
...
@@ -273,7 +270,7 @@ from_chars_result aton_float(const char* str, int len, T& value) { // NOLINT
break
;
}
uint8_t
cv
=
kAsciiToInt
[
reinterpret_cast
<
const
uint8_t
&>
(
c
)];
if
(
unlikely
(
cv
>=
base
))
{
if
(
UNLIKELY
(
cv
>=
base
))
{
value
=
static_cast
<
T
>
(
lval
);
result
.
ptr
=
str
+
i
;
return
result
;
...
...
@@ -287,7 +284,7 @@ from_chars_result aton_float(const char* str, int len, T& value) { // NOLINT
if
(
-
1
!=
dot_pos
)
{
for
(;
i
<
len
;
++
i
)
{
uint8_t
cv
=
kAsciiToInt
[
reinterpret_cast
<
const
uint8_t
&>
(
str
[
i
])];
if
(
unlikely
(
cv
>=
base
))
{
if
(
UNLIKELY
(
cv
>=
base
))
{
result
.
ptr
=
str
+
i
;
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录