mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Performance : Cache result of some string manipulation functions
These functions get called quite often, and popped up based on profiling.
This commit is contained in:
parent
e426364fd5
commit
8daf25ffb3
@ -31,6 +31,7 @@
|
|||||||
#include "RiaTextStringTools.h"
|
#include "RiaTextStringTools.h"
|
||||||
#include "RiaVersionInfo.h"
|
#include "RiaVersionInfo.h"
|
||||||
#include "RiaViewRedrawScheduler.h"
|
#include "RiaViewRedrawScheduler.h"
|
||||||
|
#include "RiaWellNameComparer.h"
|
||||||
|
|
||||||
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
||||||
#include "HoloLensCommands/RicHoloLensSessionManager.h"
|
#include "HoloLensCommands/RicHoloLensSessionManager.h"
|
||||||
@ -782,6 +783,8 @@ void RiaApplication::closeProject()
|
|||||||
m_project->close();
|
m_project->close();
|
||||||
m_commandQueue.clear();
|
m_commandQueue.clear();
|
||||||
|
|
||||||
|
RiaWellNameComparer::clearCache();
|
||||||
|
|
||||||
onProjectClosed();
|
onProjectClosed();
|
||||||
|
|
||||||
caf::PdmUiModelChangeDetector::instance()->reset();
|
caf::PdmUiModelChangeDetector::instance()->reset();
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
std::map<QString, QString> RiaWellNameComparer::sm_nameWithoutPrefix;
|
||||||
|
std::map<QString, QString> RiaWellNameComparer::sm_matchedName;
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
@ -62,19 +65,41 @@ QString RiaWellNameComparer::tryFindMatchingWellPath( QString wellName )
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RiaWellNameComparer::tryMatchNameInList( QString searchName, const std::vector<QString>& nameList )
|
QString RiaWellNameComparer::tryMatchNameInList( QString searchName, const std::vector<QString>& nameList )
|
||||||
{
|
{
|
||||||
|
if ( sm_matchedName.count( searchName ) > 0 )
|
||||||
|
{
|
||||||
|
return sm_matchedName[searchName];
|
||||||
|
};
|
||||||
|
|
||||||
// Try exact name match
|
// Try exact name match
|
||||||
QString matchedName = tryMatchName( searchName, nameList );
|
QString matchedName = tryMatchName( searchName, nameList );
|
||||||
if ( !matchedName.isEmpty() )
|
if ( !matchedName.isEmpty() )
|
||||||
{
|
{
|
||||||
|
sm_matchedName[searchName] = matchedName;
|
||||||
return matchedName;
|
return matchedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try matching ignoring spaces, dashes and underscores
|
// Try matching ignoring spaces, dashes and underscores
|
||||||
return tryMatchName( searchName, nameList, []( const QString& str ) {
|
matchedName = tryMatchName( searchName, nameList, []( const QString& str ) {
|
||||||
QString s = str;
|
QString s = str;
|
||||||
s = removeWellNamePrefix( s );
|
s = removeWellNamePrefix( s );
|
||||||
return s.remove( ' ' ).remove( '-' ).remove( '_' );
|
return s.remove( ' ' ).remove( '-' ).remove( '_' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
if ( !matchedName.isEmpty() )
|
||||||
|
{
|
||||||
|
sm_matchedName[searchName] = matchedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaWellNameComparer::clearCache()
|
||||||
|
{
|
||||||
|
sm_nameWithoutPrefix.clear();
|
||||||
|
sm_matchedName.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -111,8 +136,18 @@ QString RiaWellNameComparer::tryMatchName( QString sea
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RiaWellNameComparer::removeWellNamePrefix( const QString& name )
|
QString RiaWellNameComparer::removeWellNamePrefix( const QString& name )
|
||||||
{
|
{
|
||||||
|
if ( sm_nameWithoutPrefix.count( name ) > 0 )
|
||||||
|
{
|
||||||
|
return sm_nameWithoutPrefix[name];
|
||||||
|
};
|
||||||
|
|
||||||
// Try to remove prefix on the format 'xx xxxx/xx-'
|
// Try to remove prefix on the format 'xx xxxx/xx-'
|
||||||
std::regex pattern( "^.*\\d*[/]\\d*[-_]" );
|
std::regex pattern( "^.*\\d*[/]\\d*[-_]" );
|
||||||
|
|
||||||
return QString::fromStdString( std::regex_replace( name.toStdString(), pattern, "" ) );
|
auto withoutPrefix = std::regex_replace( name.toStdString(), pattern, "" );
|
||||||
|
auto qWithoutPrefix = QString::fromStdString( withoutPrefix );
|
||||||
|
|
||||||
|
sm_nameWithoutPrefix[name] = qWithoutPrefix;
|
||||||
|
|
||||||
|
return qWithoutPrefix;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
@ -32,13 +34,18 @@ class RiaWellNameComparer
|
|||||||
public:
|
public:
|
||||||
static QString tryFindMatchingSimWellName( QString searchName );
|
static QString tryFindMatchingSimWellName( QString searchName );
|
||||||
static QString tryFindMatchingWellPath( QString wellName );
|
static QString tryFindMatchingWellPath( QString wellName );
|
||||||
|
|
||||||
static QString tryMatchNameInList( QString searchName, const std::vector<QString>& nameList );
|
static QString tryMatchNameInList( QString searchName, const std::vector<QString>& nameList );
|
||||||
|
|
||||||
|
static void clearCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString tryMatchName( QString searchName,
|
static QString tryMatchName( QString searchName,
|
||||||
const std::vector<QString>& nameList,
|
const std::vector<QString>& nameList,
|
||||||
std::function<QString( QString )> stringFormatter = nullptr );
|
std::function<QString( QString )> stringFormatter = nullptr );
|
||||||
|
|
||||||
static QString removeWellNamePrefix( const QString& name );
|
static QString removeWellNamePrefix( const QString& name );
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::map<QString, QString> sm_nameWithoutPrefix;
|
||||||
|
static std::map<QString, QString> sm_matchedName;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user