Skip to content

Commit

Permalink
Replace uses of boost flat_map and flat_set with robin_map and robin_…
Browse files Browse the repository at this point in the history
…set (AcademySoftwareFoundation#4191)

A tiny bit more progress towards AcademySoftwareFoundation#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 <ckulla@gmail.com>
  • Loading branch information
fpsunflower authored and lgritz committed Apr 13, 2024
1 parent 0101781 commit 2e3fdd4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
19 changes: 17 additions & 2 deletions src/libOpenImageIO/color_ocio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <vector>

#include <boost/container/flat_map.hpp>
#include <tsl/robin_map.h>

#include <OpenImageIO/Imath.h>

Expand Down Expand Up @@ -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;
Expand All @@ -126,8 +136,13 @@ class ColorProcCacheKey {
};


struct ColorProcCacheKeyHasher {
size_t operator()(const ColorProcCacheKey& c) const { return c.hash; }
};


typedef boost::container::flat_map<ColorProcCacheKey, ColorProcessorHandle>
typedef tsl::robin_map<ColorProcCacheKey, ColorProcessorHandle,
ColorProcCacheKeyHasher>
ColorProcessorMap;


Expand Down
14 changes: 7 additions & 7 deletions src/libOpenImageIO/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <sstream>
#include <vector>

#include <boost/container/flat_map.hpp>
#include <tsl/robin_map.h>

#include <OpenImageIO/fmath.h>
#include <OpenImageIO/imageio.h>
Expand All @@ -27,8 +27,8 @@ using namespace pvt;

class TagMap::Impl {
public:
typedef boost::container::flat_map<int, const TagInfo*> tagmap_t;
typedef boost::container::flat_map<std::string, const TagInfo*> namemap_t;
typedef tsl::robin_map<int, const TagInfo*> tagmap_t;
typedef tsl::robin_map<std::string, const TagInfo*> namemap_t;
// Name map is lower case so it's effectively case-insensitive

Impl(string_view mapname, cspan<TagInfo> tag_table)
Expand Down Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libOpenImageIO/xmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <iostream>

#include <boost/container/flat_map.hpp>
#include <tsl/robin_map.h>

#include <OpenImageIO/fmath.h>
#include <OpenImageIO/imageio.h>
Expand Down Expand Up @@ -222,7 +222,7 @@ static XMPtag xmptag[] = {


class XMPtagMap {
typedef boost::container::flat_map<std::string, const XMPtag*> tagmap_t;
typedef tsl::robin_map<std::string, const XMPtag*> tagmap_t;
// Key is lower case so it's effectively case-insensitive
public:
XMPtagMap(const XMPtag* tag_table)
Expand Down
1 change: 0 additions & 1 deletion src/libtexture/imagecache_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <tsl/robin_map.h>

#include <boost/container/flat_map.hpp>
#include <boost/thread/tss.hpp>

#include <OpenImageIO/Imath.h>
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function (setup_oiio_util_library targetname)
target_include_directories (${targetname}
PUBLIC
$<INSTALL_INTERFACE:include>
PRIVATE
${ROBINMAP_INCLUDES}
)
target_link_libraries (${targetname}
PUBLIC
Expand Down
4 changes: 2 additions & 2 deletions src/libutil/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# include <tbb/task_arena.h>
#endif

#include <boost/container/flat_map.hpp>
#include <tsl/robin_map.h>

#ifdef _WIN32
# include <windows.h>
Expand Down Expand Up @@ -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<std::thread::id, int> m_worker_threadids;
mutable tsl::robin_map<std::thread::id, int> m_worker_threadids;
mutable spin_mutex m_worker_threadids_mutex;
};

Expand Down
4 changes: 3 additions & 1 deletion src/oiiotool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<TARGET_NAME_IF_EXISTS:OpenEXR::OpenEXR>
$<TARGET_NAME_IF_EXISTS:OpenEXR::IlmImf>
Expand Down
4 changes: 2 additions & 2 deletions src/oiiotool/oiiotool.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <memory>
#include <stack>

#include <boost/container/flat_set.hpp>
#include <tsl/robin_set.h>

#include <OpenImageIO/half.h>

Expand Down Expand Up @@ -1099,7 +1099,7 @@ class OiiotoolOp {
std::vector<ImageBuf*> m_img;
std::vector<string_view> m_args;
ParamValueList m_options;
typedef boost::container::flat_set<int> FastIntSet;
typedef tsl::robin_set<int> 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;
Expand Down

0 comments on commit 2e3fdd4

Please sign in to comment.