mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -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 "RiaVersionInfo.h"
|
||||
#include "RiaViewRedrawScheduler.h"
|
||||
#include "RiaWellNameComparer.h"
|
||||
|
||||
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
||||
#include "HoloLensCommands/RicHoloLensSessionManager.h"
|
||||
@ -782,6 +783,8 @@ void RiaApplication::closeProject()
|
||||
m_project->close();
|
||||
m_commandQueue.clear();
|
||||
|
||||
RiaWellNameComparer::clearCache();
|
||||
|
||||
onProjectClosed();
|
||||
|
||||
caf::PdmUiModelChangeDetector::instance()->reset();
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
#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 )
|
||||
{
|
||||
if ( sm_matchedName.count( searchName ) > 0 )
|
||||
{
|
||||
return sm_matchedName[searchName];
|
||||
};
|
||||
|
||||
// Try exact name match
|
||||
QString matchedName = tryMatchName( searchName, nameList );
|
||||
if ( !matchedName.isEmpty() )
|
||||
{
|
||||
sm_matchedName[searchName] = matchedName;
|
||||
return matchedName;
|
||||
}
|
||||
|
||||
// Try matching ignoring spaces, dashes and underscores
|
||||
return tryMatchName( searchName, nameList, []( const QString& str ) {
|
||||
matchedName = tryMatchName( searchName, nameList, []( const QString& str ) {
|
||||
QString s = str;
|
||||
s = removeWellNamePrefix( s );
|
||||
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 )
|
||||
{
|
||||
if ( sm_nameWithoutPrefix.count( name ) > 0 )
|
||||
{
|
||||
return sm_nameWithoutPrefix[name];
|
||||
};
|
||||
|
||||
// Try to remove prefix on the format 'xx xxxx/xx-'
|
||||
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
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
@ -32,13 +34,18 @@ class RiaWellNameComparer
|
||||
public:
|
||||
static QString tryFindMatchingSimWellName( QString searchName );
|
||||
static QString tryFindMatchingWellPath( QString wellName );
|
||||
|
||||
static QString tryMatchNameInList( QString searchName, const std::vector<QString>& nameList );
|
||||
|
||||
static void clearCache();
|
||||
|
||||
private:
|
||||
static QString tryMatchName( QString searchName,
|
||||
const std::vector<QString>& nameList,
|
||||
std::function<QString( QString )> stringFormatter = nullptr );
|
||||
|
||||
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