Move webassets structures to constexpr
clang-tidy warned on some data structures that, if they throw, the
exceptions can't be caught.
Move these data structures to constexpr equivalents to save some memory.
Tested:
Loaded webui. Worked as intended, and static files loaded properly.
Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: I331ebfc2451f0cc0a82a1b70d325008c9c80401a
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 7cf6c93..9944dfd 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -29,7 +29,7 @@
inline void requestRoutes(App& app)
{
- const static boost::container::flat_map<const char*, const char*, CmpStr>
+ constexpr static std::array<std::pair<const char*, const char*>, 17>
contentTypes{
{{".css", "text/css;charset=UTF-8"},
{".html", "text/html;charset=UTF-8"},
@@ -115,17 +115,24 @@
}
const char* contentType = nullptr;
- auto contentTypeIt = contentTypes.find(extension.c_str());
- if (contentTypeIt == contentTypes.end())
+ for (const std::pair<const char*, const char*>& ext : contentTypes)
+ {
+ if (ext.first == nullptr || ext.second == nullptr)
+ {
+ continue;
+ }
+ if (extension == ext.first)
+ {
+ contentType = ext.second;
+ }
+ }
+
+ if (contentType == nullptr)
{
BMCWEB_LOG_ERROR << "Cannot determine content-type for "
<< absolutePath << " with extension "
<< extension;
}
- else
- {
- contentType = contentTypeIt->second;
- }
app.routeDynamic(webpath)(
[absolutePath, contentType,