summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/Library_comphelper.mk1
-rw-r--r--comphelper/source/misc/graphicmimetype.cxx50
2 files changed, 29 insertions, 22 deletions
diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index ed0a2eed1dfb..ca666ade6135 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -34,6 +34,7 @@ $(eval $(call gb_Library_add_defs,comphelper,\
$(eval $(call gb_Library_use_externals,comphelper,\
gpgmepp \
boost_headers \
+ frozen \
icuuc \
icu_headers \
zlib \
diff --git a/comphelper/source/misc/graphicmimetype.cxx b/comphelper/source/misc/graphicmimetype.cxx
index a9bc0e504ea5..73845d79547a 100644
--- a/comphelper/source/misc/graphicmimetype.cxx
+++ b/comphelper/source/misc/graphicmimetype.cxx
@@ -33,6 +33,10 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
+#include <frozen/bits/defines.h>
+#include <frozen/bits/elsa_std.h>
+#include <frozen/unordered_map.h>
+
using namespace css;
using namespace css::beans;
using namespace css::graphic;
@@ -43,29 +47,31 @@ namespace comphelper
{
OUString GraphicMimeTypeHelper::GetMimeTypeForExtension(std::string_view rExt)
{
- struct XMLGraphicMimeTypeMapper
- {
- const char* pExt;
- const char* pMimeType;
- };
-
- static const XMLGraphicMimeTypeMapper aMapper[]
- = { { "gif", "image/gif" }, { "png", "image/png" }, { "jpg", "image/jpeg" },
- { "tif", "image/tiff" }, { "svg", "image/svg+xml" }, { "pdf", "application/pdf" },
- { "wmf", "image/x-wmf" }, { "emf", "image/x-emf" }, { "eps", "image/x-eps" },
- { "bmp", "image/bmp" }, { "pct", "image/x-pict" }, { "svm", "image/x-svm" } };
-
- OUString aMimeType;
+#if defined(_MSC_VER) && !defined(__clang__)
+ static const
+#else
+ static constexpr
+#endif
+ auto aMapper
+ = frozen::make_unordered_map<std::string_view, OUString>(
+ { { "gif", u"image/gif"_ustr },
+ { "png", u"image/png"_ustr },
+ { "jpg", u"image/jpeg"_ustr },
+ { "tif", u"image/tiff"_ustr },
+ { "svg", u"image/svg+xml"_ustr },
+ { "pdf", u"application/pdf"_ustr },
+ { "wmf", u"image/x-wmf"_ustr },
+ { "emf", u"image/x-emf"_ustr },
+ { "eps", u"image/x-eps"_ustr },
+ { "bmp", u"image/bmp"_ustr },
+ { "pct", u"image/x-pict"_ustr },
+ { "svm", u"image/x-svm"_ustr } });
+
+ auto iterator = aMapper.find(rExt);
+ if (iterator != aMapper.end())
+ return iterator->second;
- size_t const nCount = std::size(aMapper);
- for (size_t i = 0; (i < nCount) && aMimeType.isEmpty(); ++i)
- {
- if (rExt == aMapper[i].pExt)
- aMimeType = OUString(aMapper[i].pMimeType, strlen(aMapper[i].pMimeType),
- RTL_TEXTENCODING_ASCII_US);
- }
-
- return aMimeType;
+ return OUString();
}
OUString GraphicMimeTypeHelper::GetMimeTypeForXGraphic(const Reference<XGraphic>& xGraphic)