Skip to content

Commit ee79710

Browse files
committed
Simplify code
1 parent 0385651 commit ee79710

File tree

5 files changed

+158
-343
lines changed

5 files changed

+158
-343
lines changed

include/archspec/detect.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ std::vector<const Microarchitecture*> compatible_microarchitectures(const Detect
6464
std::vector<const Microarchitecture*> compatible_microarchitectures(const DetectedCpuInfo& info,
6565
const std::string& arch);
6666

67+
/**
68+
* Compare microarchitectures for sorting: prefers more ancestors and more features
69+
* Returns true if a < b (a is less specific than b)
70+
*/
71+
inline bool compare_microarch_specificity(const Microarchitecture* a, const Microarchitecture* b) {
72+
size_t a_depth = a->ancestors().size();
73+
size_t b_depth = b->ancestors().size();
74+
if (a_depth != b_depth)
75+
return a_depth < b_depth;
76+
return a->features().size() < b->features().size();
77+
}
78+
6779
// Platform-specific detection functions
6880

6981
#if defined(__linux__) || defined(__FreeBSD__)

include/archspec/microarchitecture.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,17 @@ class MicroarchitectureDatabase {
162162
MicroarchitectureDatabase& operator=(const MicroarchitectureDatabase&) = delete;
163163

164164
void load_embedded_data();
165-
void fill_target(const std::string& name, const void* json_data);
166-
bool load_from_json_internal(const void* json_ptr);
167165

168166
std::map<std::string, Microarchitecture> targets_;
169167
std::map<std::string, std::set<std::string>> feature_aliases_;
170168
std::map<std::string, std::set<std::string>> family_features_;
171169
std::map<std::string, std::string> darwin_flags_;
172170
std::map<std::string, std::string> arm_vendors_;
173171
bool loaded_ = false;
172+
173+
// Allow JSON parsing helper access to private members
174+
friend bool load_json_into_database(MicroarchitectureDatabase& db,
175+
const std::string& json_data);
174176
};
175177

176178
// Convenience function to get a microarchitecture by name

0 commit comments

Comments
 (0)