From 2a4a70ed21f62a59b6b78c768631938a1cecb16b Mon Sep 17 00:00:00 2001 From: Rajendra Singh Date: Mon, 25 Feb 2019 00:49:58 +0530 Subject: [PATCH] Pass the arguments by reference instead of by copy to improve the performance Close #5341 --- PowerEditor/src/Parameters.h | 2 +- .../src/WinControls/FileBrowser/fileBrowser.cpp | 8 ++++---- .../src/WinControls/FileBrowser/fileBrowser.h | 14 +++++++------- .../WinControls/FunctionList/functionParser.cpp | 2 +- .../WinControls/FunctionList/functionParser.h | 16 ++++++++-------- .../src/WinControls/shortcut/shortcut.cpp | 6 +++--- PowerEditor/src/WinControls/shortcut/shortcut.h | 10 +++++----- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index e4798fd6..f38bffdb 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -162,7 +162,7 @@ private: struct sessionFileInfo : public Position { - sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, Position pos, const TCHAR *backupFilePath, FILETIME originalFileLastModifTimestamp, const MapPosition & mapPos) : + sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, const Position& pos, const TCHAR *backupFilePath, FILETIME originalFileLastModifTimestamp, const MapPosition & mapPos) : _encoding(encoding), Position(pos), _originalFileLastModifTimestamp(originalFileLastModifTimestamp), _mapPos(mapPos) { if (fn) _fileName = fn; diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 002ec614..02c355f0 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -1027,7 +1027,7 @@ generic_string FileBrowser::getSelectedItemPath() const return itemPath; } -bool FileBrowser::addInTree(generic_string rootPath, generic_string addItemFullPath, HTREEITEM node, vector linarPathArray) +bool FileBrowser::addInTree(const generic_string& rootPath, const generic_string& addItemFullPath, HTREEITEM node, vector linarPathArray) { if (node == nullptr) // it's a root. Search the right root with rootPath { @@ -1083,7 +1083,7 @@ bool FileBrowser::addInTree(generic_string rootPath, generic_string addItemFullP } } -HTREEITEM FileBrowser::findInTree(generic_string rootPath, HTREEITEM node, std::vector linarPathArray) +HTREEITEM FileBrowser::findInTree(const generic_string& rootPath, HTREEITEM node, std::vector linarPathArray) { if (node == nullptr) // it's a root. Search the right root with rootPath { @@ -1122,7 +1122,7 @@ HTREEITEM FileBrowser::findInTree(generic_string rootPath, HTREEITEM node, std:: } } -bool FileBrowser::deleteFromTree(generic_string rootPath, HTREEITEM node, std::vector linarPathArray) +bool FileBrowser::deleteFromTree(const generic_string& rootPath, HTREEITEM node, std::vector linarPathArray) { HTREEITEM foundItem = findInTree(rootPath, node, linarPathArray); if (foundItem == nullptr) @@ -1133,7 +1133,7 @@ bool FileBrowser::deleteFromTree(generic_string rootPath, HTREEITEM node, std::v return true; } -bool FileBrowser::renameInTree(generic_string rootPath, HTREEITEM node, std::vector linarPathArrayFrom, const generic_string & renameTo) +bool FileBrowser::renameInTree(const generic_string& rootPath, HTREEITEM node, std::vector linarPathArrayFrom, const generic_string & renameTo) { HTREEITEM foundItem = findInTree(rootPath, node, linarPathArrayFrom); if (foundItem == nullptr) diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h index 39c0108e..f1f4a97e 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h @@ -75,11 +75,11 @@ friend class FolderUpdater; public: FolderInfo(const generic_string & name, FolderInfo *parent) : _name(name), _parent(parent) {}; - void setRootPath(generic_string rootPath) { _rootPath = rootPath; }; + void setRootPath(const generic_string& rootPath) { _rootPath = rootPath; }; generic_string getRootPath() const { return _rootPath; }; - void setName(generic_string name) { _name = name; }; + void setName(const generic_string& name) { _name = name; }; generic_string getName() const { return _name; }; - void addFile(generic_string fn) { _files.push_back(FileInfo(fn, this)); }; + void addFile(const generic_string& fn) { _files.push_back(FileInfo(fn, this)); }; void addSubFolder(FolderInfo subDirectoryStructure) { _subFolders.push_back(subDirectoryStructure); }; bool addToStructure(generic_string & fullpath, std::vector linarPathArray); @@ -147,10 +147,10 @@ public: HTREEITEM getRootFromFullPath(const generic_string & rootPath) const; HTREEITEM findChildNodeFromName(HTREEITEM parent, generic_string); - bool addInTree(generic_string rootPath, generic_string addItemFullPath, HTREEITEM node, std::vector linarPathArray); - HTREEITEM findInTree(generic_string rootPath, HTREEITEM node, std::vector linarPathArray); - bool deleteFromTree(generic_string rootPath, HTREEITEM node, std::vector linarPathArray); - bool renameInTree(generic_string rootPath, HTREEITEM node, std::vector linarPathArrayFrom, const generic_string & renameTo); + bool addInTree(const generic_string& rootPath, const generic_string& addItemFullPath, HTREEITEM node, std::vector linarPathArray); + HTREEITEM findInTree(const generic_string& rootPath, HTREEITEM node, std::vector linarPathArray); + bool deleteFromTree(const generic_string& rootPath, HTREEITEM node, std::vector linarPathArray); + bool renameInTree(const generic_string& rootPath, HTREEITEM node, std::vector linarPathArrayFrom, const generic_string & renameTo); std::vector getRoots() const; generic_string getSelectedItemPath() const; diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp index 84699c45..796b8302 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -43,7 +43,7 @@ FunctionParsersManager::~FunctionParsersManager() delete _pXmlFuncListDoc; } -bool FunctionParsersManager::init(generic_string xmlPath, ScintillaEditView ** ppEditView) +bool FunctionParsersManager::init(const generic_string& xmlPath, ScintillaEditView ** ppEditView) { _ppEditView = ppEditView; bool loadOkay = false; diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.h b/PowerEditor/src/WinControls/FunctionList/functionParser.h index 7f491060..e65f6b45 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.h +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.h @@ -43,7 +43,7 @@ class FunctionParser { friend class FunctionParsersManager; public: - FunctionParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string functionExpr, std::vector functionNameExprArray, std::vector classNameExprArray): + FunctionParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, const generic_string& functionExpr, const std::vector& functionNameExprArray, const std::vector& classNameExprArray): _id(id), _displayName(displayName), _commentExpr(commentExpr?commentExpr:TEXT("")), _functionExpr(functionExpr), _functionNameExprArray(functionNameExprArray), _classNameExprArray(classNameExprArray){}; virtual void parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")) = 0; @@ -66,8 +66,8 @@ protected: class FunctionZoneParser : public FunctionParser { public: - FunctionZoneParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole, - std::vector classNameExprArray, generic_string functionExpr, std::vector functionNameExprArray): + FunctionZoneParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, const generic_string& rangeExpr, const generic_string& openSymbole, const generic_string& closeSymbole, + const std::vector& classNameExprArray, const generic_string& functionExpr, const std::vector& functionNameExprArray): FunctionParser(id, displayName, commentExpr, functionExpr, functionNameExprArray, classNameExprArray), _rangeExpr(rangeExpr), _openSymbole(openSymbole), _closeSymbole(closeSymbole) {}; void parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); @@ -89,8 +89,8 @@ class FunctionUnitParser : public FunctionParser { public: FunctionUnitParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, - generic_string mainExpr, std::vector functionNameExprArray, - std::vector classNameExprArray): FunctionParser(id, displayName, commentExpr, mainExpr, functionNameExprArray, classNameExprArray) + const generic_string& mainExpr, const std::vector& functionNameExprArray, + const std::vector& classNameExprArray): FunctionParser(id, displayName, commentExpr, mainExpr, functionNameExprArray, classNameExprArray) {} void parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); @@ -99,8 +99,8 @@ public: class FunctionMixParser : public FunctionZoneParser { public: - FunctionMixParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole, - std::vector classNameExprArray, generic_string functionExpr, std::vector functionNameExprArray, FunctionUnitParser *funcUnitPaser): + FunctionMixParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, const generic_string& rangeExpr, const generic_string& openSymbole, const generic_string& closeSymbole, + const std::vector& classNameExprArray, const generic_string& functionExpr, const std::vector& functionNameExprArray, FunctionUnitParser *funcUnitPaser): FunctionZoneParser(id, displayName, commentExpr, rangeExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray), _funcUnitPaser(funcUnitPaser){}; ~FunctionMixParser() @@ -143,7 +143,7 @@ class FunctionParsersManager final public: ~FunctionParsersManager(); - bool init(generic_string xmlPath, ScintillaEditView ** ppEditView); + bool init(const generic_string& xmlPath, ScintillaEditView ** ppEditView); bool parse(std::vector & foundInfos, const AssociationInfo & assoInfo); void writeFunctionListXml(const TCHAR *destFoder) const; diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index fa7e32a4..dfc77ce0 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -611,7 +611,7 @@ void Accelerator::updateFullMenu() { ::DrawMenuBar(_hMenuParent); } -void Accelerator::updateMenuItemByCommand(CommandShortcut csc) +void Accelerator::updateMenuItemByCommand(const CommandShortcut& csc) { int cmdID = csc.getID(); @@ -887,7 +887,7 @@ void ScintillaAccelerator::updateKeys() } } -void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) +void ScintillaAccelerator::updateMenuItemByID(const ScintillaKeyMap& skm, int id) { const int commandSize = 64; TCHAR cmdName[commandSize]; @@ -1107,7 +1107,7 @@ INT_PTR CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPARA //return FALSE; } -CommandShortcut::CommandShortcut(Shortcut sc, long id) : Shortcut(sc), _id(id) { +CommandShortcut::CommandShortcut(const Shortcut& sc, long id) : Shortcut(sc), _id(id) { if ( _id < IDM_EDIT) _category = TEXT("File"); else if ( _id < IDM_SEARCH) diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index 8faac433..68535a7d 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -194,7 +194,7 @@ protected : class CommandShortcut : public Shortcut { public: - CommandShortcut(Shortcut sc, long id); + CommandShortcut(const Shortcut& sc, long id); unsigned long getID() const {return _id;}; void setID(unsigned long id) { _id = id;}; const TCHAR * getCategory() const { return _category.c_str(); }; @@ -207,7 +207,7 @@ private : class ScintillaKeyMap : public Shortcut { public: - ScintillaKeyMap(Shortcut sc, unsigned long scintillaKeyID, unsigned long id): Shortcut(sc), _menuCmdID(id), _scintillaKeyID(scintillaKeyID) { + ScintillaKeyMap(const Shortcut& sc, unsigned long scintillaKeyID, unsigned long id): Shortcut(sc), _menuCmdID(id), _scintillaKeyID(scintillaKeyID) { _keyCombos.clear(); _keyCombos.push_back(_keyCombo); _keyCombo._key = 0; @@ -311,7 +311,7 @@ typedef std::vector Macro; class MacroShortcut : public CommandShortcut { friend class NppParameters; public: - MacroShortcut(Shortcut sc, Macro macro, int id) : CommandShortcut(sc, id), _macro(macro) {_canModifyName = true;}; + MacroShortcut(const Shortcut& sc, const Macro& macro, int id) : CommandShortcut(sc, id), _macro(macro) {_canModifyName = true;}; Macro & getMacro() {return _macro;}; private: Macro _macro; @@ -384,7 +384,7 @@ private: ACCEL *_pAccelArray = nullptr; int _nbAccelItems = 0; - void updateMenuItemByCommand(CommandShortcut csc); + void updateMenuItemByCommand(const CommandShortcut& csc); }; class ScintillaAccelerator { //Handles accelerator keys for scintilla @@ -398,5 +398,5 @@ private: HWND _hMenuParent = nullptr; std::vector _vScintillas; - void updateMenuItemByID(ScintillaKeyMap skm, int id); + void updateMenuItemByID(const ScintillaKeyMap& skm, int id); };