mirror of https://github.com/Icinga/icinga2.git
parent
ade12dc27a
commit
85a380c443
|
@ -194,6 +194,8 @@ class: class_attribute_list T_CLASS T_IDENTIFIER inherits_specifier type_base_sp
|
|||
|
||||
$$->Fields = *$7;
|
||||
delete $7;
|
||||
|
||||
ClassCompiler::OptimizeStructLayout($$->Fields);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -106,6 +106,38 @@ unsigned long ClassCompiler::SDBM(const std::string& str, size_t len = std::stri
|
|||
return hash;
|
||||
}
|
||||
|
||||
static int TypePreference(const std::string& type)
|
||||
{
|
||||
if (type == "Value")
|
||||
return 0;
|
||||
else if (type == "String")
|
||||
return 1;
|
||||
else if (type == "double")
|
||||
return 2;
|
||||
else if (type.find("::Ptr") != std::string::npos)
|
||||
return 3;
|
||||
else if (type == "int")
|
||||
return 4;
|
||||
else
|
||||
return 5;
|
||||
}
|
||||
|
||||
static bool FieldLayoutCmp(const Field& a, const Field& b)
|
||||
{
|
||||
return TypePreference(a.Type) < TypePreference(b.Type);
|
||||
}
|
||||
|
||||
static bool FieldTypeCmp(const Field& a, const Field& b)
|
||||
{
|
||||
return a.Type < b.Type;
|
||||
}
|
||||
|
||||
void ClassCompiler::OptimizeStructLayout(std::vector<Field>& fields)
|
||||
{
|
||||
std::sort(fields.begin(), fields.end(), FieldTypeCmp);
|
||||
std::stable_sort(fields.begin(), fields.end(), FieldLayoutCmp);
|
||||
}
|
||||
|
||||
void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
|
||||
{
|
||||
std::vector<Field>::const_iterator it;
|
||||
|
|
|
@ -145,6 +145,8 @@ public:
|
|||
static void CompileFile(const std::string& path);
|
||||
static void CompileStream(const std::string& path, std::istream *stream);
|
||||
|
||||
static void OptimizeStructLayout(std::vector<Field>& fields);
|
||||
|
||||
private:
|
||||
std::string m_Path;
|
||||
std::istream *m_Input;
|
||||
|
|
Loading…
Reference in New Issue