未验证 提交 6c440d28 编写于 作者: R Ray Liu 提交者: GitHub

Merge pull request #1091 from xiebaiyuan/develop

use larger buffer to avoid of big string issue
...@@ -79,13 +79,13 @@ struct Variant { ...@@ -79,13 +79,13 @@ struct Variant {
template <typename T, typename... Args> template <typename T, typename... Args>
void Set(Args &&... args) { void Set(Args &&... args) {
helper::Destroy(type_id, &data.data); helper::Destroy(type_id, data.data);
new (&data.data) T(std::forward<Args>(args)...); new (data.data) T(std::forward<Args>(args)...);
type_id = typeid(T).hash_code(); type_id = typeid(T).hash_code();
} }
void SetString(std::string &string) { void SetString(std::string &string) {
// helper::Destroy(type_id, &data); helper::Destroy(type_id, data.data);
type_id = typeid(std::string).hash_code(); type_id = typeid(std::string).hash_code();
strcpy(data.data, string.c_str()); strcpy(data.data, string.c_str());
} }
...@@ -109,7 +109,7 @@ struct Variant { ...@@ -109,7 +109,7 @@ struct Variant {
"stl lib with string copy)"); "stl lib with string copy)");
exit(0); exit(0);
} else if (type_id == typeid(T).hash_code()) { } else if (type_id == typeid(T).hash_code()) {
return *const_cast<T *>(reinterpret_cast<const T *>(&data)); return *const_cast<T *>(reinterpret_cast<const T *>(data.data));
} else { } else {
PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant"); PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant");
exit(0); exit(0);
...@@ -122,7 +122,8 @@ struct Variant { ...@@ -122,7 +122,8 @@ struct Variant {
static inline size_t invalid_type() { return typeid(void).hash_code(); } static inline size_t invalid_type() { return typeid(void).hash_code(); }
typedef VariantHelper<Ts...> helper; typedef VariantHelper<Ts...> helper;
size_t type_id; size_t type_id;
RawData<helper::size> data; // todo use an anto size to suite this.
RawData<64> data;
}; };
template <typename T> template <typename T>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册