mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 04:21:13 +00:00
Add arbitrary string type to the native object API (#4218)
* Custom strings are very common for optimizations around small objects or growth style optimizations, i.e.: grow at 1.57 times vs doubling vs.. A second common strategy is to cooperate w/ the memory allocator see FBString[1] and seastar[2] string for examples. [1] fbstring: https://github.com/facebook/folly/blob/master/folly/docs/FBString.md [2] sstring: https://github.com/scylladb/seastar/blob/master/core/sstring.hh
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
9c25ecdcd1
commit
f2071e4f80
@@ -362,6 +362,15 @@ class CppGenerator : public BaseGenerator {
|
||||
return attr ? attr->constant : parser_.opts.cpp_object_api_pointer_type;
|
||||
}
|
||||
|
||||
const std::string NativeString(const FieldDef *field) {
|
||||
auto attr = field ? field->attributes.Lookup("cpp_str_type") : nullptr;
|
||||
auto &ret = attr ? attr->constant : parser_.opts.cpp_object_api_string_type;
|
||||
if (ret.empty()) {
|
||||
return "std::string";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string GenTypeNativePtr(const std::string &type, const FieldDef *field,
|
||||
bool is_constructor) {
|
||||
auto &ptr_type = PtrType(field);
|
||||
@@ -383,7 +392,7 @@ class CppGenerator : public BaseGenerator {
|
||||
const FieldDef &field) {
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_STRING: {
|
||||
return "std::string";
|
||||
return NativeString(&field);
|
||||
}
|
||||
case BASE_TYPE_VECTOR: {
|
||||
const auto type_name = GenTypeNative(type.VectorType(), true, field);
|
||||
|
||||
Reference in New Issue
Block a user