mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-13 04:42:12 +03:00
Replace std unordered_map with robin_hood hashmap in some cases. Testing perf improvements (if any).
This commit is contained in:
31
include/eepp/core/containers.hpp
Normal file
31
include/eepp/core/containers.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef EE_CONTAINERS_HPP
|
||||
#define EE_CONTAINERS_HPP
|
||||
|
||||
#ifdef EEPP_NO_THIRDPARTY_CONTAINERS
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#else
|
||||
#include <eepp/thirdparty/robin_hood.h>
|
||||
#endif
|
||||
|
||||
namespace EE {
|
||||
|
||||
#ifdef EEPP_NO_THIRDPARTY_CONTAINERS
|
||||
|
||||
template <typename Key, typename Value> using UnorderedMap = std::ununordered_map<Key, Value>;
|
||||
|
||||
template <typename Key, typename Value> using UnorderedSet = std::unordered_set<Key, Value>;
|
||||
|
||||
#else
|
||||
|
||||
template <typename Key, typename Value>
|
||||
using UnorderedMap = robin_hood::unordered_flat_map<Key, Value>;
|
||||
|
||||
template <typename Key, typename Value>
|
||||
using UnorderedSet = robin_hood::unordered_flat_set<Key, Value>;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace EE
|
||||
|
||||
#endif // EE_CONTAINERS_HPP
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef EE_CORE_CORE_HPP
|
||||
#define EE_CORE_CORE_HPP
|
||||
|
||||
#include <eepp/core/containers.hpp>
|
||||
#include <eepp/core/debug.hpp>
|
||||
#include <eepp/core/memorymanager.hpp>
|
||||
#include <eepp/core/string.hpp>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <eepp/graphics/font.hpp>
|
||||
#include <eepp/graphics/texture.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace EE { namespace System {
|
||||
class Pack;
|
||||
@@ -141,9 +140,8 @@ class EE_API FontTrueType : public Font {
|
||||
unsigned int height; ///< Height of the row
|
||||
};
|
||||
|
||||
typedef std::unordered_map<Uint64, Glyph>
|
||||
GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||
typedef std::unordered_map<Uint64, GlyphDrawable*> GlyphDrawableTable;
|
||||
typedef UnorderedMap<Uint64, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||
typedef UnorderedMap<Uint64, GlyphDrawable*> GlyphDrawableTable;
|
||||
|
||||
struct Page {
|
||||
explicit Page( const Uint32 fontInternalId );
|
||||
@@ -206,8 +204,8 @@ class EE_API FontTrueType : public Font {
|
||||
bool mEnableDynamicMonospace{ false };
|
||||
bool mIsBold{ false };
|
||||
bool mIsItalic{ false };
|
||||
mutable std::unordered_map<unsigned int, unsigned int> mClosestCharacterSize;
|
||||
mutable std::unordered_map<Uint32, Uint32> mCodePointIndexCache;
|
||||
mutable UnorderedMap<unsigned int, unsigned int> mClosestCharacterSize;
|
||||
mutable UnorderedMap<Uint32, Uint32> mCodePointIndexCache;
|
||||
FontHinting mHinting{ FontHinting::Full };
|
||||
FontAntialiasing mAntialiasing{ FontAntialiasing::Grayscale };
|
||||
FontTrueType* mFontBold{ nullptr };
|
||||
|
||||
2544
include/eepp/thirdparty/robin_hood.h
vendored
Normal file
2544
include/eepp/thirdparty/robin_hood.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -65,10 +65,10 @@ class EE_API StyleSheet {
|
||||
protected:
|
||||
Uint32 mMarker{ 0 };
|
||||
std::vector<std::shared_ptr<StyleSheetStyle>> mNodes;
|
||||
std::unordered_map<size_t, StyleSheetStyleVector> mNodeIndex;
|
||||
UnorderedMap<size_t, StyleSheetStyleVector> mNodeIndex;
|
||||
MediaQueryList::vector mMediaQueryList;
|
||||
KeyframesDefinitionMap mKeyframesMap;
|
||||
using ElementDefinitionCache = std::unordered_map<size_t, std::shared_ptr<ElementDefinition>>;
|
||||
using ElementDefinitionCache = UnorderedMap<size_t, std::shared_ptr<ElementDefinition>>;
|
||||
mutable ElementDefinitionCache mNodeCache;
|
||||
|
||||
void addMediaQueryList( MediaQueryList::ptr list );
|
||||
|
||||
@@ -204,7 +204,7 @@ class EE_API StyleSheetProperty {
|
||||
std::vector<VariableFunctionCache> checkVars( const std::string& value );
|
||||
};
|
||||
|
||||
typedef std::unordered_map<Uint32, StyleSheetProperty> StyleSheetProperties;
|
||||
typedef UnorderedMap<Uint32, StyleSheetProperty> StyleSheetProperties;
|
||||
|
||||
}}} // namespace EE::UI::CSS
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define EE_UI_CSS_STYLESHEETVARIABLE_HPP
|
||||
|
||||
#include <eepp/config.hpp>
|
||||
#include <eepp/core/containers.hpp>
|
||||
#include <eepp/core/string.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -43,7 +44,7 @@ class EE_API StyleSheetVariable {
|
||||
Uint32 mSpecificity;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<Uint32, StyleSheetVariable> StyleSheetVariables;
|
||||
typedef UnorderedMap<Uint32, StyleSheetVariable> StyleSheetVariables;
|
||||
|
||||
}}} // namespace EE::UI::CSS
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class EE_API SyntaxHighlighter {
|
||||
protected:
|
||||
TextDocument* mDoc;
|
||||
std::unordered_map<size_t, TokenizedLine> mLines;
|
||||
std::unordered_map<size_t, TokenizedLine> mTokenizerLines;
|
||||
UnorderedMap<size_t, TokenizedLine> mTokenizerLines;
|
||||
Mutex mLinesMutex;
|
||||
Int64 mFirstInvalidLine;
|
||||
Int64 mMaxWantedLine;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
../../include/eepp/audio/soundsource.hpp
|
||||
../../include/eepp/audio/soundstream.hpp
|
||||
../../include/eepp/config.hpp
|
||||
../../include/eepp/core/containers.hpp
|
||||
../../include/eepp/core/core.hpp
|
||||
../../include/eepp/core/debug.hpp
|
||||
../../include/eepp/core.hpp
|
||||
|
||||
@@ -403,7 +403,7 @@ const Glyph& FontTrueType::getGlyphByIndex( Uint32 index, unsigned int character
|
||||
Glyph glyph =
|
||||
loadGlyph( index, characterSize, bold, italic, outlineThickness, page, maxWidth );
|
||||
|
||||
return glyphs.insert( std::make_pair( key, glyph ) ).first->second;
|
||||
return glyphs.emplace( key, glyph ).first->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -588,7 +588,8 @@ void Text::getWidthInfo() {
|
||||
|
||||
for ( std::size_t i = 0; i < mString.size(); ++i ) {
|
||||
CharID = static_cast<Int32>( mString.at( i ) );
|
||||
Glyph glyph = mFont->getGlyph( CharID, mRealFontSize, bold, italic, mOutlineThickness );
|
||||
const Glyph& glyph =
|
||||
mFont->getGlyph( CharID, mRealFontSize, bold, italic, mOutlineThickness );
|
||||
|
||||
if ( CharID != '\r' && CharID != '\t' ) {
|
||||
Width += mFont->getKerning( prevChar, CharID, mRealFontSize, bold, italic,
|
||||
@@ -911,6 +912,12 @@ void Text::ensureGeometryUpdate() {
|
||||
mOutlineVertices.clear();
|
||||
mBounds = Rectf();
|
||||
|
||||
mVertices.reserve( mString.size() * GLi->quadVertexs() );
|
||||
mGlyphCache.reserve( mString.size() );
|
||||
|
||||
if ( mOutlineThickness != 0.f )
|
||||
mOutlineVertices.reserve( mString.size() * GLi->quadVertexs() );
|
||||
|
||||
// No font or text: nothing to draw
|
||||
if ( !mFont || mString.empty() )
|
||||
return;
|
||||
@@ -1172,7 +1179,7 @@ void Text::cacheWidth() {
|
||||
if ( !mCachedWidthNeedUpdate )
|
||||
return;
|
||||
|
||||
if ( NULL != mFont && mString.size() ) {
|
||||
if ( NULL != mFont && !mString.empty() ) {
|
||||
getWidthInfo();
|
||||
mCachedWidthNeedUpdate = false;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user