Change most associative containers to their respective 'unordered' version

This commit is contained in:
Vittorio Romeo 2021-12-06 11:36:16 +00:00
parent 93410afdc7
commit 51ebeaf383
14 changed files with 52 additions and 50 deletions

View File

@ -7,7 +7,7 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <map> #include <unordered_map>
namespace namespace
@ -18,7 +18,7 @@ namespace
sf::Text value; sf::Text value;
}; };
typedef std::map<std::string, JoystickObject> Texts; typedef std::unordered_map<std::string, JoystickObject> Texts;
Texts texts; Texts texts;
std::ostringstream sstr; std::ostringstream sstr;
float threshold = 0.1f; float threshold = 0.1f;

View File

@ -33,7 +33,7 @@
#include <SFML/System/Time.hpp> #include <SFML/System/Time.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
#include <set> #include <unordered_set>
namespace sf namespace sf
@ -267,7 +267,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef std::set<Sound*> SoundList; //!< Set of unique sound instances typedef std::unordered_set<Sound*> SoundList; //!< Set of unique sound instances
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data

View File

@ -32,7 +32,7 @@
#include <SFML/Graphics/Glyph.hpp> #include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Texture.hpp> #include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <map> #include <unordered_map>
#include <string> #include <string>
#include <vector> #include <vector>
@ -327,7 +327,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef std::map<Uint64, Glyph> GlyphTable; //!< Table mapping a codepoint to its glyph typedef std::unordered_map<Uint64, Glyph> GlyphTable; //!< Table mapping a codepoint to its glyph
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Structure defining a page of glyphs /// \brief Structure defining a page of glyphs
@ -387,7 +387,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef std::map<unsigned int, Page> PageTable; //!< Table mapping a character size to its page (texture) typedef std::unordered_map<unsigned int, Page> PageTable; //!< Table mapping a character size to its page (texture)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data

View File

@ -34,8 +34,8 @@
#include <SFML/System/NonCopyable.hpp> #include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
#include <map>
#include <string> #include <string>
#include <unordered_map>
namespace sf namespace sf
@ -739,8 +739,8 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef std::map<int, const Texture*> TextureTable; typedef std::unordered_map<int, const Texture*> TextureTable;
typedef std::map<std::string, int> UniformTable; typedef std::unordered_map<std::string, int> UniformTable;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data

View File

@ -173,7 +173,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef std::map<std::string, std::string> FieldTable; typedef std::map<std::string, std::string> FieldTable; // Use an ordered map for predictable payloads
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
@ -333,7 +333,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Types // Types
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef std::map<std::string, std::string> FieldTable; typedef std::map<std::string, std::string> FieldTable; // Use an ordered map for predictable payloads
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data

View File

@ -39,7 +39,7 @@
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <map> #include <unordered_map>
// GL_QUADS is unavailable on OpenGL ES, thus we need to define GL_QUADS ourselves // GL_QUADS is unavailable on OpenGL ES, thus we need to define GL_QUADS ourselves
@ -71,7 +71,7 @@ namespace
// Map to help us detect whether a different RenderTarget // Map to help us detect whether a different RenderTarget
// has been activated within a single context // has been activated within a single context
typedef std::map<sf::Uint64, sf::Uint64> ContextRenderTargetMap; typedef std::unordered_map<sf::Uint64, sf::Uint64> ContextRenderTargetMap;
ContextRenderTargetMap contextRenderTargetMap; ContextRenderTargetMap contextRenderTargetMap;
// Check if a RenderTarget with the given ID is active in the current context // Check if a RenderTarget with the given ID is active in the current context

View File

@ -32,6 +32,8 @@
#include <SFML/System/Lock.hpp> #include <SFML/System/Lock.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <utility> #include <utility>
#include <unordered_map>
#include <unordered_set>
#include <set> #include <set>
@ -40,7 +42,7 @@ namespace
// Set to track all active FBO mappings // Set to track all active FBO mappings
// This is used to free active FBOs while their owning // This is used to free active FBOs while their owning
// RenderTextureImplFBO is still alive // RenderTextureImplFBO is still alive
std::set<std::map<sf::Uint64, unsigned int>*> frameBuffers; std::unordered_set<std::unordered_map<sf::Uint64, unsigned int>*> frameBuffers;
// Set to track all stale FBOs // Set to track all stale FBOs
// This is used to free stale FBOs after their owning // This is used to free stale FBOs after their owning
@ -84,9 +86,9 @@ namespace
sf::Uint64 contextId = sf::Context::getActiveContextId(); sf::Uint64 contextId = sf::Context::getActiveContextId();
// Destroy active frame buffer objects // Destroy active frame buffer objects
for (std::set<std::map<sf::Uint64, unsigned int>*>::iterator frameBuffersIter = frameBuffers.begin(); frameBuffersIter != frameBuffers.end(); ++frameBuffersIter) for (std::unordered_set<std::unordered_map<sf::Uint64, unsigned int>*>::iterator frameBuffersIter = frameBuffers.begin(); frameBuffersIter != frameBuffers.end(); ++frameBuffersIter)
{ {
for (std::map<sf::Uint64, unsigned int>::iterator iter = (*frameBuffersIter)->begin(); iter != (*frameBuffersIter)->end(); ++iter) for (std::unordered_map<sf::Uint64, unsigned int>::iterator iter = (*frameBuffersIter)->begin(); iter != (*frameBuffersIter)->end(); ++iter)
{ {
if (iter->first == contextId) if (iter->first == contextId)
{ {
@ -160,10 +162,10 @@ RenderTextureImplFBO::~RenderTextureImplFBO()
} }
// Move all frame buffer objects to stale set // Move all frame buffer objects to stale set
for (std::map<Uint64, unsigned int>::iterator iter = m_frameBuffers.begin(); iter != m_frameBuffers.end(); ++iter) for (std::unordered_map<Uint64, unsigned int>::iterator iter = m_frameBuffers.begin(); iter != m_frameBuffers.end(); ++iter)
staleFrameBuffers.emplace(iter->first, iter->second); staleFrameBuffers.emplace(iter->first, iter->second);
for (std::map<Uint64, unsigned int>::iterator iter = m_multisampleFrameBuffers.begin(); iter != m_multisampleFrameBuffers.end(); ++iter) for (std::unordered_map<Uint64, unsigned int>::iterator iter = m_multisampleFrameBuffers.begin(); iter != m_multisampleFrameBuffers.end(); ++iter)
staleFrameBuffers.emplace(iter->first, iter->second); staleFrameBuffers.emplace(iter->first, iter->second);
// Clean up FBOs // Clean up FBOs
@ -540,7 +542,7 @@ bool RenderTextureImplFBO::activate(bool active)
{ {
Lock lock(mutex); Lock lock(mutex);
std::map<Uint64, unsigned int>::iterator iter; std::unordered_map<Uint64, unsigned int>::iterator iter;
if (m_multisample) if (m_multisample)
{ {
@ -594,8 +596,8 @@ void RenderTextureImplFBO::updateTexture(unsigned int)
Lock lock(mutex); Lock lock(mutex);
std::map<Uint64, unsigned int>::iterator iter = m_frameBuffers.find(contextId); std::unordered_map<Uint64, unsigned int>::iterator iter = m_frameBuffers.find(contextId);
std::map<Uint64, unsigned int>::iterator multisampleIter = m_multisampleFrameBuffers.find(contextId); std::unordered_map<Uint64, unsigned int>::iterator multisampleIter = m_multisampleFrameBuffers.find(contextId);
if ((iter != m_frameBuffers.end()) && (multisampleIter != m_multisampleFrameBuffers.end())) if ((iter != m_frameBuffers.end()) && (multisampleIter != m_multisampleFrameBuffers.end()))
{ {

View File

@ -31,7 +31,7 @@
#include <SFML/Graphics/RenderTextureImpl.hpp> #include <SFML/Graphics/RenderTextureImpl.hpp>
#include <SFML/Window/Context.hpp> #include <SFML/Window/Context.hpp>
#include <SFML/Window/GlResource.hpp> #include <SFML/Window/GlResource.hpp>
#include <map> #include <unordered_map>
namespace sf namespace sf
@ -136,8 +136,8 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::map<Uint64, unsigned int> m_frameBuffers; //!< OpenGL frame buffer objects per context std::unordered_map<Uint64, unsigned int> m_frameBuffers; //!< OpenGL frame buffer objects per context
std::map<Uint64, unsigned int> m_multisampleFrameBuffers; //!< Optional per-context OpenGL frame buffer objects with multisample attachments std::unordered_map<Uint64, unsigned int> m_multisampleFrameBuffers; //!< Optional per-context OpenGL frame buffer objects with multisample attachments
unsigned int m_depthStencilBuffer; //!< Optional depth/stencil buffer attached to the frame buffer unsigned int m_depthStencilBuffer; //!< Optional depth/stencil buffer attached to the frame buffer
unsigned int m_colorBuffer; //!< Optional multisample color buffer attached to the frame buffer unsigned int m_colorBuffer; //!< Optional multisample color buffer attached to the frame buffer
unsigned int m_width; //!< Width of the attachments unsigned int m_width; //!< Width of the attachments

View File

@ -34,7 +34,7 @@
#include <android/native_activity.h> #include <android/native_activity.h>
#include <android/configuration.h> #include <android/configuration.h>
#include <vector> #include <vector>
#include <map> #include <unordered_map>
#include <string> #include <string>
#include <fstream> #include <fstream>
@ -73,7 +73,7 @@ struct ActivityStates
void (*forwardEvent)(const Event& event); void (*forwardEvent)(const Event& event);
int (*processEvent)(int fd, int events, void* data); int (*processEvent)(int fd, int events, void* data);
std::map<int, Vector2i> touchEvents; std::unordered_map<int, Vector2i> touchEvents;
Vector2i mousePosition; Vector2i mousePosition;
bool isButtonPressed[Mouse::ButtonCount]; bool isButtonPressed[Mouse::ButtonCount];

View File

@ -32,7 +32,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <cstring> #include <cstring>
#include <map> #include <unordered_map>
#include <string> #include <string>
#include <utility> #include <utility>
@ -49,8 +49,8 @@
namespace namespace
{ {
std::map<unsigned int, std::string> plugged; std::unordered_map<unsigned int, std::string> plugged;
std::map<int, std::pair<int, int> > hatValueMap; std::unordered_map<int, std::pair<int, int> > hatValueMap;
bool isJoystick(const char *name) bool isJoystick(const char *name)
{ {

View File

@ -36,7 +36,7 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <string> #include <string>
#include <set> #include <unordered_map>
#include <utility> #include <utility>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -176,7 +176,7 @@ namespace
// context is going to be destroyed // context is going to be destroyed
// Unshareable OpenGL resources rely on this to clean up properly // Unshareable OpenGL resources rely on this to clean up properly
// whenever a context containing them is destroyed // whenever a context containing them is destroyed
typedef std::set<std::pair<sf::ContextDestroyCallback, void*> > ContextDestroyCallbacks; typedef std::unordered_map<sf::ContextDestroyCallback, void*> ContextDestroyCallbacks;
ContextDestroyCallbacks contextDestroyCallbacks; ContextDestroyCallbacks contextDestroyCallbacks;
// This structure contains all the state necessary to // This structure contains all the state necessary to

View File

@ -32,7 +32,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <cstring> #include <cstring>
#include <map> #include <unordered_map>
#include <string> #include <string>
#include <utility> #include <utility>
@ -44,8 +44,8 @@
namespace namespace
{ {
std::map<unsigned int, std::string> plugged; std::unordered_map<unsigned int, std::string> plugged;
std::map<int, std::pair<int, int> > hatValueMap; std::unordered_map<int, std::pair<int, int> > hatValueMap;
bool isJoystick(const char *name) bool isJoystick(const char *name)
{ {

View File

@ -34,7 +34,7 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/hid/IOHIDDevice.h> #include <IOKit/hid/IOHIDDevice.h>
#include <IOKit/hid/IOHIDKeys.h> #include <IOKit/hid/IOHIDKeys.h>
#include <map> #include <unordered_map>
#include <vector> #include <vector>
namespace sf namespace sf
@ -117,7 +117,7 @@ private:
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef long Location; typedef long Location;
typedef std::map<sf::Joystick::Axis, IOHIDElementRef> AxisMap; typedef std::unordered_map<sf::Joystick::Axis, IOHIDElementRef> AxisMap;
typedef std::vector<IOHIDElementRef> ButtonsVector; typedef std::vector<IOHIDElementRef> ButtonsVector;
AxisMap m_axis; ///< Axes (but not POV/Hat) of the joystick AxisMap m_axis; ///< Axes (but not POV/Hat) of the joystick

View File

@ -32,7 +32,7 @@
#include <X11/keysym.h> #include <X11/keysym.h>
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <map> #include <unordered_map>
namespace namespace
@ -42,7 +42,7 @@ namespace
unsigned int referenceCount = 0; unsigned int referenceCount = 0;
sf::Mutex mutex; sf::Mutex mutex;
typedef std::map<std::string, Atom> AtomMap; typedef std::unordered_map<std::string, Atom> AtomMap;
AtomMap atoms; AtomMap atoms;
} }