From 5472c84bf18b3264b6443cb58468dd475df5dac9 Mon Sep 17 00:00:00 2001 From: Christopher Kulla Date: Tue, 9 Apr 2024 17:18:47 -0700 Subject: [PATCH] Replace uses of boost flat_map and flat_set with robin_map and robin_set (#4191) A tiny bit more progress towards #4158. None of the code was actually dependent on the fact that these containers are sorted by key. Switching to the robin containers instead removes one less use of boost in the project. Signed-off-by: Chris Kulla --- src/libOpenImageIO/color_ocio.cpp | 19 +++++++++++++++++-- src/libOpenImageIO/exif.cpp | 14 +++++++------- src/libOpenImageIO/xmp.cpp | 4 ++-- src/libtexture/imagecache_pvt.h | 1 - src/libutil/CMakeLists.txt | 2 ++ src/libutil/thread.cpp | 4 ++-- src/oiiotool/CMakeLists.txt | 4 +++- src/oiiotool/oiiotool.h | 4 ++-- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/libOpenImageIO/color_ocio.cpp b/src/libOpenImageIO/color_ocio.cpp index 76ed1d9daa..9d3a44efda 100644 --- a/src/libOpenImageIO/color_ocio.cpp +++ b/src/libOpenImageIO/color_ocio.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include @@ -113,6 +113,16 @@ class ColorProcCacheKey { b.view, b.file, b.inverse); } + friend bool operator==(const ColorProcCacheKey& a, + const ColorProcCacheKey& b) + { + return std::tie(a.hash, a.inputColorSpace, a.outputColorSpace, + a.context_key, a.context_value, a.looks, a.display, + a.view, a.file, a.inverse) + == std::tie(b.hash, b.inputColorSpace, b.outputColorSpace, + b.context_key, b.context_value, b.looks, b.display, + b.view, b.file, b.inverse); + } ustring inputColorSpace; ustring outputColorSpace; ustring context_key; @@ -126,8 +136,13 @@ class ColorProcCacheKey { }; +struct ColorProcCacheKeyHasher { + size_t operator()(const ColorProcCacheKey& c) const { return c.hash; } +}; + -typedef boost::container::flat_map +typedef tsl::robin_map ColorProcessorMap; diff --git a/src/libOpenImageIO/exif.cpp b/src/libOpenImageIO/exif.cpp index 56ad1f2475..57a23965fb 100644 --- a/src/libOpenImageIO/exif.cpp +++ b/src/libOpenImageIO/exif.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -27,8 +27,8 @@ using namespace pvt; class TagMap::Impl { public: - typedef boost::container::flat_map tagmap_t; - typedef boost::container::flat_map namemap_t; + typedef tsl::robin_map tagmap_t; + typedef tsl::robin_map namemap_t; // Name map is lower case so it's effectively case-insensitive Impl(string_view mapname, cspan tag_table) @@ -568,11 +568,11 @@ enum GPSTag { static const TagInfo gps_tag_table[] = { // clang-format off - { GPSTAG_VERSIONID, "GPS:VersionID", TIFF_BYTE, 4, version4uint8_handler }, + { GPSTAG_VERSIONID, "GPS:VersionID", TIFF_BYTE, 4, version4uint8_handler }, { GPSTAG_LATITUDEREF, "GPS:LatitudeRef", TIFF_ASCII, 2 }, { GPSTAG_LATITUDE, "GPS:Latitude", TIFF_RATIONAL, 3 }, { GPSTAG_LONGITUDEREF, "GPS:LongitudeRef", TIFF_ASCII, 2 }, - { GPSTAG_LONGITUDE, "GPS:Longitude", TIFF_RATIONAL, 3 }, + { GPSTAG_LONGITUDE, "GPS:Longitude", TIFF_RATIONAL, 3 }, { GPSTAG_ALTITUDEREF, "GPS:AltitudeRef", TIFF_BYTE, 1 }, { GPSTAG_ALTITUDE, "GPS:Altitude", TIFF_RATIONAL, 1 }, { GPSTAG_TIMESTAMP, "GPS:TimeStamp", TIFF_RATIONAL, 3 }, @@ -590,7 +590,7 @@ static const TagInfo gps_tag_table[] = { { GPSTAG_DESTLATITUDEREF, "GPS:DestLatitudeRef", TIFF_ASCII, 2 }, { GPSTAG_DESTLATITUDE, "GPS:DestLatitude", TIFF_RATIONAL, 3 }, { GPSTAG_DESTLONGITUDEREF, "GPS:DestLongitudeRef", TIFF_ASCII, 2 }, - { GPSTAG_DESTLONGITUDE, "GPS:DestLongitude", TIFF_RATIONAL, 3 }, + { GPSTAG_DESTLONGITUDE, "GPS:DestLongitude", TIFF_RATIONAL, 3 }, { GPSTAG_DESTBEARINGREF, "GPS:DestBearingRef", TIFF_ASCII, 2 }, { GPSTAG_DESTBEARING, "GPS:DestBearing", TIFF_RATIONAL, 1 }, { GPSTAG_DESTDISTANCEREF, "GPS:DestDistanceRef", TIFF_ASCII, 2 }, @@ -756,7 +756,7 @@ add_exif_item_to_spec(ImageSpec& spec, const char* name, #if 0 if (dirp->tdir_type == TIFF_UNDEFINED || dirp->tdir_type == TIFF_BYTE) { // Add it as bytes - const void *addr = dirp->tdir_count <= 4 ? (const void *) &dirp->tdir_offset + const void *addr = dirp->tdir_count <= 4 ? (const void *) &dirp->tdir_offset : (const void *) &buf[dirp->tdir_offset]; spec.attribute (name, TypeDesc(TypeDesc::UINT8, dirp->tdir_count), addr); } diff --git a/src/libOpenImageIO/xmp.cpp b/src/libOpenImageIO/xmp.cpp index 9c13b582b5..c46e8d215c 100644 --- a/src/libOpenImageIO/xmp.cpp +++ b/src/libOpenImageIO/xmp.cpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -222,7 +222,7 @@ static XMPtag xmptag[] = { class XMPtagMap { - typedef boost::container::flat_map tagmap_t; + typedef tsl::robin_map tagmap_t; // Key is lower case so it's effectively case-insensitive public: XMPtagMap(const XMPtag* tag_table) diff --git a/src/libtexture/imagecache_pvt.h b/src/libtexture/imagecache_pvt.h index 681cca0e16..d06eb50e42 100644 --- a/src/libtexture/imagecache_pvt.h +++ b/src/libtexture/imagecache_pvt.h @@ -12,7 +12,6 @@ #include -#include #include #include diff --git a/src/libutil/CMakeLists.txt b/src/libutil/CMakeLists.txt index 0e3f4cd81a..d393a5874f 100644 --- a/src/libutil/CMakeLists.txt +++ b/src/libutil/CMakeLists.txt @@ -45,6 +45,8 @@ function (setup_oiio_util_library targetname) target_include_directories (${targetname} PUBLIC $ + PRIVATE + ${ROBINMAP_INCLUDES} ) target_link_libraries (${targetname} PUBLIC diff --git a/src/libutil/thread.cpp b/src/libutil/thread.cpp index 52744d8ba6..22f7cab035 100644 --- a/src/libutil/thread.cpp +++ b/src/libutil/thread.cpp @@ -33,7 +33,7 @@ # include #endif -#include +#include #ifdef _WIN32 # include @@ -360,7 +360,7 @@ class thread_pool::Impl { int m_size { 0 }; // Number of threads in the queue std::mutex mutex; std::condition_variable cv; - mutable boost::container::flat_map m_worker_threadids; + mutable tsl::robin_map m_worker_threadids; mutable spin_mutex m_worker_threadids_mutex; }; diff --git a/src/oiiotool/CMakeLists.txt b/src/oiiotool/CMakeLists.txt index 212a442d78..3b6a09fc94 100644 --- a/src/oiiotool/CMakeLists.txt +++ b/src/oiiotool/CMakeLists.txt @@ -2,7 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 # https://github.com/AcademySoftwareFoundation/OpenImageIO -fancy_add_executable (LINK_LIBRARIES +fancy_add_executable (SYSTEM_INCLUDE_DIRS + ${ROBINMAP_INCLUDES} + LINK_LIBRARIES OpenImageIO $ $ diff --git a/src/oiiotool/oiiotool.h b/src/oiiotool/oiiotool.h index f5d389d486..a746fd851f 100644 --- a/src/oiiotool/oiiotool.h +++ b/src/oiiotool/oiiotool.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include @@ -1099,7 +1099,7 @@ class OiiotoolOp { std::vector m_img; std::vector m_args; ParamValueList m_options; - typedef boost::container::flat_set FastIntSet; + typedef tsl::robin_set FastIntSet; FastIntSet subimage_includes; // Subimages to operate on (empty == all) FastIntSet subimage_excludes; // Subimages to skip for the op setup_func_t m_setup_func;