Skip to content

Commit 9abeb45

Browse files
committed
refactor GetNamespace to simplify logic and improve readability
1 parent 7cf5d51 commit 9abeb45

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

modules/core/util/include/util.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@ int GetNumThreads();
5151
template <typename T>
5252
constexpr std::string_view GetNamespace() {
5353
#if defined(_MSC_VER)
54-
constexpr auto func = std::string_view{__FUNCSIG__};
54+
constexpr std::string_view func{__FUNCSIG__};
5555
auto start = func.find("GetNamespace<") + 13;
5656
for (auto p : {"class ", "struct ", "enum ", "union "})
57-
if (func.substr(start).starts_with(p)) start += p.size();
57+
if (func.substr(start).starts_with(p)) {
58+
start += std::string_view{p}.size();
59+
break;
60+
}
5861
#else
59-
constexpr auto func = std::string_view{__PRETTY_FUNCTION__};
62+
constexpr std::string_view func{__PRETTY_FUNCTION__};
6063
auto start = func.find("T = ") + 4;
6164
#endif
6265
auto end = func.find_first_of(";]> ,>", start);
63-
if (end == std::string_view::npos) return {};
64-
auto ns_end = func.rfind("::", end);
65-
return (ns_end != std::string_view::npos && ns_end > start) ? func.substr(start, ns_end - start) : std::string_view{};
66+
auto ns = func.substr(start, end - start);
67+
auto pos = ns.rfind("::");
68+
return (pos != std::string_view::npos) ? ns.substr(0, pos) : std::string_view{};
6669
}
6770

6871
inline std::shared_ptr<nlohmann::json> InitJSONPtr() { return std::make_shared<nlohmann::json>(); }

0 commit comments

Comments
 (0)