mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
eepp: Performance optimizations.
This commit is contained in:
@@ -105,11 +105,12 @@ class EE_API FontTrueType : public Font {
|
||||
unsigned int height; ///< Height of the row
|
||||
};
|
||||
|
||||
typedef std::map<Uint64, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||
typedef std::map<Uint64, GlyphDrawable*> GlyphDrawableTable;
|
||||
typedef std::unordered_map<Uint64, Glyph>
|
||||
GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||
typedef std::unordered_map<Uint64, GlyphDrawable*> GlyphDrawableTable;
|
||||
|
||||
struct Page {
|
||||
Page( const Uint32 fontInternalId );
|
||||
explicit Page( const Uint32 fontInternalId );
|
||||
|
||||
~Page();
|
||||
|
||||
@@ -166,11 +167,8 @@ class EE_API FontTrueType : public Font {
|
||||
bool mEnableEmojiFallback{ true };
|
||||
bool mEnableFallbackFont{ true };
|
||||
bool mEnableDynamicMonospace{ false };
|
||||
mutable std::map<unsigned int, unsigned int> mClosestCharacterSize;
|
||||
mutable std::map<Uint32, Uint32> mCodePointIndexCache;
|
||||
|
||||
Uint64 getIndexKey( Uint32 fontInternalId, Uint32 index, bool bold,
|
||||
Float outlineThickness ) const;
|
||||
mutable std::unordered_map<unsigned int, unsigned int> mClosestCharacterSize;
|
||||
mutable std::unordered_map<Uint32, Uint32> mCodePointIndexCache;
|
||||
|
||||
void updateFontInternalId();
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <eepp/ui/doc/syntaxtokenizer.hpp>
|
||||
#include <eepp/ui/doc/textdocument.hpp>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace EE { namespace UI { namespace Doc {
|
||||
|
||||
@@ -16,7 +16,7 @@ struct TokenizedLine {
|
||||
|
||||
class EE_API SyntaxHighlighter {
|
||||
public:
|
||||
SyntaxHighlighter( TextDocument* doc );
|
||||
explicit SyntaxHighlighter( TextDocument* doc );
|
||||
|
||||
void changeDoc( TextDocument* doc );
|
||||
|
||||
@@ -40,7 +40,7 @@ class EE_API SyntaxHighlighter {
|
||||
|
||||
protected:
|
||||
TextDocument* mDoc;
|
||||
std::map<size_t, TokenizedLine> mLines;
|
||||
std::unordered_map<size_t, TokenizedLine> mLines;
|
||||
Int64 mFirstInvalidLine;
|
||||
Int64 mMaxWantedLine;
|
||||
TokenizedLine tokenizeLine( const size_t& line, const Uint64& state );
|
||||
|
||||
@@ -593,9 +593,9 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
Vector2f getRelativeScreenPosition( const TextPosition& pos );
|
||||
|
||||
bool getShowLinesRelativePosition() const;
|
||||
void showLinesRelativePosition(bool showLinesRelativePosition);
|
||||
void showLinesRelativePosition( bool showLinesRelativePosition );
|
||||
|
||||
protected:
|
||||
protected:
|
||||
struct LastXOffset {
|
||||
TextPosition position{ 0, 0 };
|
||||
Float offset{ 0.f };
|
||||
@@ -662,7 +662,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
SyntaxColorScheme mColorScheme;
|
||||
UIScrollBar* mVScrollBar;
|
||||
UIScrollBar* mHScrollBar;
|
||||
std::map<size_t, LastXOffset> mLastXOffset;
|
||||
std::unordered_map<size_t, LastXOffset> mLastXOffset;
|
||||
KeyBindings mKeyBindings;
|
||||
std::unordered_set<std::string> mUnlockedCmd;
|
||||
Clock mLastDoubleClick;
|
||||
@@ -687,7 +687,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
Text text;
|
||||
String::HashType hash;
|
||||
};
|
||||
mutable std::map<Int64, TextLine> mTextCache;
|
||||
mutable std::unordered_map<Int64, TextLine> mTextCache;
|
||||
Tools::UIDocFindReplace* mFindReplace{ nullptr };
|
||||
struct PluginRequestedSpace {
|
||||
UICodeEditorPlugin* plugin;
|
||||
@@ -699,6 +699,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
std::vector<PluginRequestedSpace> mPluginTopSpaces;
|
||||
Float mPluginsTopSpace{ 0 };
|
||||
Uint64 mLastExecuteEventId{ 0 };
|
||||
Text mLineTextCache;
|
||||
|
||||
UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands = true,
|
||||
const bool& autoRegisterBaseKeybindings = true );
|
||||
|
||||
@@ -43,14 +43,6 @@ template <typename T, typename U> inline T reinterpret( const U& input ) {
|
||||
return output;
|
||||
}
|
||||
|
||||
// Combine outline thickness, boldness and font glyph index into a single 64-bit key
|
||||
EE::Uint64 combine( float outlineThickness, bool bold, EE::Uint32 index,
|
||||
EE::Uint32 fontInternalId ) {
|
||||
return ( static_cast<EE::Uint64>( reinterpret<EE::Uint32>( fontInternalId ) ) << 48 ) |
|
||||
( static_cast<EE::Uint64>( reinterpret<EE::Uint32>( outlineThickness * 100 ) ) << 33 ) |
|
||||
( static_cast<EE::Uint64>( bold ) << 32 ) | index;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
@@ -58,6 +50,14 @@ namespace EE { namespace Graphics {
|
||||
static std::map<std::string, Uint32> fontsInternalIds;
|
||||
static std::atomic<Uint32> fontInternalIdCounter{ 0 };
|
||||
|
||||
// Combine outline thickness, boldness and font glyph index into a single 64-bit key
|
||||
static inline Uint64 getIndexKey( Uint32 fontInternalId, Uint32 index, bool bold,
|
||||
Float outlineThickness ) {
|
||||
return ( static_cast<EE::Uint64>( reinterpret<EE::Uint32>( fontInternalId ) ) << 48 ) |
|
||||
( static_cast<EE::Uint64>( reinterpret<EE::Uint32>( outlineThickness * 100 ) ) << 33 ) |
|
||||
( static_cast<EE::Uint64>( bold ) << 32 ) | index;
|
||||
}
|
||||
|
||||
FontTrueType* FontTrueType::New( const std::string& FontName ) {
|
||||
return eeNew( FontTrueType, ( FontName ) );
|
||||
}
|
||||
@@ -348,11 +348,6 @@ const FontTrueType::Info& FontTrueType::getInfo() const {
|
||||
return mInfo;
|
||||
}
|
||||
|
||||
Uint64 FontTrueType::getIndexKey( Uint32 fontInternalId, Uint32 index, bool bold,
|
||||
Float outlineThickness ) const {
|
||||
return combine( outlineThickness, bold, index, fontInternalId );
|
||||
}
|
||||
|
||||
void FontTrueType::updateFontInternalId() {
|
||||
auto fontInternalId = fontsInternalIds.find( mInfo.family );
|
||||
if ( fontsInternalIds.end() == fontInternalId ) {
|
||||
|
||||
@@ -267,11 +267,11 @@ Node* Node::setParent( Node* parent ) {
|
||||
|
||||
bool Node::isParentOf( const Node* node ) const {
|
||||
eeASSERT( NULL != node );
|
||||
Node* tParent = node->getParent();
|
||||
Node* tParent = node->mParentNode;
|
||||
while ( NULL != tParent ) {
|
||||
if ( this == tParent )
|
||||
return true;
|
||||
tParent = tParent->getParent();
|
||||
tParent = tParent->mParentNode;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,11 +65,6 @@ bool Process::create( const std::string& command, const Uint32& options,
|
||||
}
|
||||
envStrings.push_back( NULL );
|
||||
|
||||
std::string cwd;
|
||||
if ( !workingDirectory.empty() ) {
|
||||
cwd = FileSystem::getCurrentWorkingDirectory();
|
||||
}
|
||||
|
||||
auto ret = 0 == subprocess_create_ex( strings.data(), options, envStrings.data(),
|
||||
!workingDirectory.empty() ? workingDirectory.c_str()
|
||||
: nullptr,
|
||||
|
||||
@@ -1573,8 +1573,6 @@ void UICodeEditor::onDocumentLineCountChange( const size_t&, const size_t& ) {
|
||||
|
||||
void UICodeEditor::onDocumentLineChanged( const Int64& lineNumber ) {
|
||||
mDoc->getHighlighter()->invalidate( lineNumber );
|
||||
if ( mFont && !mFont->isMonospace() )
|
||||
updateLineCache( lineNumber );
|
||||
|
||||
if ( !mHighlightWord.isEmpty() )
|
||||
updateHighlightWordCache();
|
||||
@@ -1755,12 +1753,8 @@ size_t UICodeEditor::characterWidth( const String& str ) const {
|
||||
|
||||
Float UICodeEditor::getTextWidth( const String& line ) const {
|
||||
if ( mFont && !mFont->isMonospace() ) {
|
||||
Float fontSize = PixelDensity::pxToDp( getCharacterSize() );
|
||||
Text txt( "", mFont, fontSize );
|
||||
txt.setTabWidth( mTabWidth );
|
||||
txt.setStyleConfig( mFontStyleConfig );
|
||||
txt.setString( line );
|
||||
return txt.getTextWidth();
|
||||
return Text::getTextWidth( mFont, getCharacterSize(), line, mFontStyleConfig.Style,
|
||||
mTabWidth );
|
||||
}
|
||||
|
||||
Float glyphWidth = getGlyphWidth();
|
||||
@@ -2713,6 +2707,9 @@ void UICodeEditor::drawLineText( const Int64& line, Vector2f position, const Flo
|
||||
ttf->setEnableFallbackFont( false );
|
||||
ttf->setEnableEmojiFallback( false );
|
||||
}
|
||||
|
||||
Text& txt = mLineTextCache;
|
||||
|
||||
for ( const auto& token : tokens ) {
|
||||
String text( pos < strLine.size() ? strLine.substr( pos, token.len ) : String() );
|
||||
pos += token.len;
|
||||
@@ -2723,12 +2720,12 @@ void UICodeEditor::drawLineText( const Int64& line, Vector2f position, const Flo
|
||||
Int64 curCharsWidth = text.size();
|
||||
Int64 curPositionChar = eefloor( mScroll.x / getGlyphWidth() );
|
||||
Float curMaxPositionChar = curPositionChar + maxWidth;
|
||||
Text txt( "", mFont, fontSize );
|
||||
txt.setFont( mFont );
|
||||
txt.setFontSize( fontSize );
|
||||
txt.setTabWidth( mTabWidth );
|
||||
const SyntaxColorScheme::Style& style = mColorScheme.getSyntaxStyle( token.type );
|
||||
txt.setStyleConfig( mFontStyleConfig );
|
||||
if ( style.style )
|
||||
txt.setStyle( style.style );
|
||||
txt.setStyle( style.style );
|
||||
txt.setColor( Color( style.color ).blendAlpha( mAlpha ) );
|
||||
|
||||
if ( isMonospace )
|
||||
|
||||
@@ -127,7 +127,6 @@ class AutoCompletePlugin : public UICodeEditorPlugin {
|
||||
};
|
||||
std::unordered_map<TextDocument*, DocCache> mDocCache;
|
||||
std::unordered_map<std::string, SymbolsList> mLangCache;
|
||||
SymbolsList mLangDirty;
|
||||
|
||||
std::vector<Suggestion> mSuggestions;
|
||||
Mutex mSuggestionsEditorMutex;
|
||||
@@ -137,15 +136,14 @@ class AutoCompletePlugin : public UICodeEditorPlugin {
|
||||
Int32 mSuggestionIndex{ 0 };
|
||||
Int32 mSuggestionsMaxVisible{ 8 };
|
||||
Int32 mSuggestionsStartIndex{ 0 };
|
||||
std::map<std::string, LSPServerCapabilities> mCapabilities;
|
||||
std::unordered_map<std::string, LSPServerCapabilities> mCapabilities;
|
||||
Mutex mCapabilitiesMutex;
|
||||
LSPSignatureHelp mSignatureHelp;
|
||||
TextPosition mSignatureHelpPosition;
|
||||
Int32 mSignatureHelpSelected{ -1 };
|
||||
Mutex mHandlesMutex;
|
||||
std::map<TextDocument*, std::vector<PluginIDType>> mHandles;
|
||||
|
||||
std::map<TextDocument*, std::atomic<bool>> mDocsUpdating;
|
||||
std::unordered_map<TextDocument*, std::vector<PluginIDType>> mHandles;
|
||||
std::unordered_map<TextDocument*, std::atomic<bool>> mDocsUpdating;
|
||||
Mutex mDocsUpdatingMutex;
|
||||
|
||||
Float mRowHeight{ 0 };
|
||||
|
||||
Reference in New Issue
Block a user