From 914b0061298894c0215203739ffe2eb5cb1a1bf8 Mon Sep 17 00:00:00 2001 From: Andreas Schenk <andreas_schenk@hms.harvard.edu> Date: Sun, 14 Oct 2012 16:26:31 -0400 Subject: [PATCH] changed size()>0 to !empty() for containers The gnu c++ size() implementation for stl containers has O(n) complexity while empty() has O(1) complexity --- modules/gfx/src/gfx_object.cc | 2 +- modules/gfx/src/surface.cc | 2 +- modules/gui/src/file_browser.cc | 2 +- modules/gui/src/messages/message_widget.cc | 2 +- modules/gui/src/python_shell/python_context_parser.cc | 2 +- modules/gui/src/python_shell/python_interpreter.cc | 2 +- modules/gui/src/python_shell/python_namespace_tree_item.cc | 2 +- modules/gui/src/python_shell/python_shell_widget.cc | 6 +++--- modules/gui/src/scene_selection.cc | 2 +- modules/gui/src/scene_win/context_menu.cc | 4 ++-- modules/gui/src/sequence_viewer/secstr_row.cc | 2 +- modules/gui/src/sequence_viewer/seq_secstr_painter.cc | 2 +- modules/gui/src/sequence_viewer/sequence_viewer.cc | 4 ++-- modules/img/base/src/progress.hh | 2 +- modules/io/src/mol/mmcif_reader.cc | 4 ++-- modules/io/src/mol/pdb_reader.cc | 4 ++-- modules/io/src/mol/pdb_writer.cc | 2 +- modules/mol/alg/src/lddt.cc | 2 +- modules/mol/base/src/impl/residue_impl.cc | 4 ++-- modules/mol/base/src/query_state.cc | 4 ++-- 20 files changed, 28 insertions(+), 28 deletions(-) diff --git a/modules/gfx/src/gfx_object.cc b/modules/gfx/src/gfx_object.cc index 63003cd5b..71181316f 100644 --- a/modules/gfx/src/gfx_object.cc +++ b/modules/gfx/src/gfx_object.cc @@ -630,7 +630,7 @@ void GfxObj::render_labels() const } void GfxObj::ReapplyColorOps(){ - if(c_ops_.size()>0){ + if(! c_ops_.empty()){ GfxObjP o=dyn_cast<GfxObj>(shared_from_this()); for(boost::ptr_vector<gfx::ColorOp>::iterator it=c_ops_.begin(); it!=c_ops_.end();++it) { diff --git a/modules/gfx/src/surface.cc b/modules/gfx/src/surface.cc index 0500e72b1..390f2d27a 100644 --- a/modules/gfx/src/surface.cc +++ b/modules/gfx/src/surface.cc @@ -152,7 +152,7 @@ geom::AlignedCuboid Surface::GetBoundingBox(bool use_tf) const -std::numeric_limits<float>::max()); std::vector<mol::SurfaceVertexID> svid_list = sh_.GetVertexIDList(); - if(svid_list.size()>0) { + if(! svid_list.empty()) { for(std::vector<mol::SurfaceVertexID>::const_iterator it=svid_list.begin(); it!=svid_list.end();++it) { geom::Vec3 pos = sh_.GetVertex(*it).position; diff --git a/modules/gui/src/file_browser.cc b/modules/gui/src/file_browser.cc index a41ff0a29..7c33f7d1f 100644 --- a/modules/gui/src/file_browser.cc +++ b/modules/gui/src/file_browser.cc @@ -267,7 +267,7 @@ void FileBrowser::ShowContextMenu(const QPoint& pos){ } menu->addAction(system_open_action); } - if(menu->actions().size()>0){ + if(! menu->actions().empty()){ menu->exec(QCursor::pos()); } } diff --git a/modules/gui/src/messages/message_widget.cc b/modules/gui/src/messages/message_widget.cc index 038840ae1..b16df9afe 100644 --- a/modules/gui/src/messages/message_widget.cc +++ b/modules/gui/src/messages/message_widget.cc @@ -216,7 +216,7 @@ void MessageWidget::ContextMenuRequested(const QPoint& pos) { QMenu* menu = new QMenu(); menu->addAction(remove_selected_action); - if (menu->actions().size() > 0) { + if (! menu->actions().empty()) { menu->popup(view_->viewport()->mapToGlobal(pos)); } } diff --git a/modules/gui/src/python_shell/python_context_parser.cc b/modules/gui/src/python_shell/python_context_parser.cc index 6b5338cea..944951114 100644 --- a/modules/gui/src/python_shell/python_context_parser.cc +++ b/modules/gui/src/python_shell/python_context_parser.cc @@ -92,7 +92,7 @@ void PythonContextParser::Parse(PythonContext*& parent_context) Parse(current_context); if (tokenizer_.CurrentToken().GetType() != PythonToken::END) current_context->AddToken(tokenizer_.CurrentToken()); - else if (current_context->GetSubContexts().size() > 0) { + else if (! current_context->GetSubContexts().empty()) { Range last_sub = current_context->GetSubContexts().back()->GetRange(); Range curr_range(current_context->GetRange().location, last_sub.End()-current_context->GetRange().location); diff --git a/modules/gui/src/python_shell/python_interpreter.cc b/modules/gui/src/python_shell/python_interpreter.cc index 08b745b71..8fe84743f 100644 --- a/modules/gui/src/python_shell/python_interpreter.cc +++ b/modules/gui/src/python_shell/python_interpreter.cc @@ -126,7 +126,7 @@ CodeBlockStatus PythonInterpreter::GetCodeBlockStatus(const QString& command) break; } bool complete=false; - if (!(lines[i].size()>0 && (lines[i][0]=='\t' || lines[i][0]==' '))) { + if (!(! lines[i].isEmpty() && (lines[i][0]=='\t' || lines[i][0]==' '))) { cmd.clear(); } while (!complete && i<lines.size()) { diff --git a/modules/gui/src/python_shell/python_namespace_tree_item.cc b/modules/gui/src/python_shell/python_namespace_tree_item.cc index 465c99f6f..b3e296090 100644 --- a/modules/gui/src/python_shell/python_namespace_tree_item.cc +++ b/modules/gui/src/python_shell/python_namespace_tree_item.cc @@ -82,7 +82,7 @@ QString PythonNamespaceTreeItem::GetName() const bool PythonNamespaceTreeItem::HasChildren() const { if (initialized_) { - return children_.size()>0; + return ! children_.empty(); } else { return true; } diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc index 8b0fd88d3..9adafdd7c 100644 --- a/modules/gui/src/python_shell/python_shell_widget.cc +++ b/modules/gui/src/python_shell/python_shell_widget.cc @@ -521,7 +521,7 @@ void PythonShellWidget::OnExecuteStateEntered() QString command=GetCommand(); QString command_trimmed=command.trimmed(); - if (command_trimmed.size()>0) { + if (! command_trimmed.isEmpty()) { unsigned int id=PythonInterpreter::Instance().RunCommand(command); output_blocks_.insert(id,textCursor().block()); history_.AppendCommand(command_trimmed,get_block_edit_mode_()); @@ -878,11 +878,11 @@ void PythonShellWidget::insertFromMimeData(const QMimeData * source) lines[i]=QString(num_spaces, '\t')+right; } text=lines.join(QString(1, QChar::LineSeparator)); - if(lines.size()>0){ + if(! lines.empty()){ machine_->setActive(multiline_active_state_); } QPlainTextEdit::insertFromMimeData(source); - if(lines.size()>0){ + if(! lines.empty()){ set_block_type_(block_edit_start_,document()->lastBlock(),BLOCKTYPE_BLOCKEDIT); } setFocus(); diff --git a/modules/gui/src/scene_selection.cc b/modules/gui/src/scene_selection.cc index f0fea54e2..2faa79d6c 100644 --- a/modules/gui/src/scene_selection.cc +++ b/modules/gui/src/scene_selection.cc @@ -197,7 +197,7 @@ void SceneSelection::Hide() { mol::EntityView SceneSelection::GetViewUnion() { mol::EntityView view; - if(views_.size()>0){ + if(! views_.empty()){ view = views_[0].GetEntityView().Copy(); for(unsigned int i = 1; i < views_.size(); i++){ view = mol::Union(view,views_[i].GetEntityView()); diff --git a/modules/gui/src/scene_win/context_menu.cc b/modules/gui/src/scene_win/context_menu.cc index 1834b71a4..370800556 100644 --- a/modules/gui/src/scene_win/context_menu.cc +++ b/modules/gui/src/scene_win/context_menu.cc @@ -125,7 +125,7 @@ void ContextMenu::ShowMenu(const QPoint& pos) gfx::EntityP view_entity = gfx::EntityP(); int cnt = 0; - if(indexes.size()>0){ + if(! indexes.empty()){ for(int i = 0; i < indexes.size(); i++){ if(indexes[i].column()==0){ cnt++; @@ -209,7 +209,7 @@ void ContextMenu::ShowMenu(const QPoint& pos) } } - if(menu->actions().size()>0){ + if(! menu->actions().empty()){ menu->popup(pos); } } diff --git a/modules/gui/src/sequence_viewer/secstr_row.cc b/modules/gui/src/sequence_viewer/secstr_row.cc index 1f7153753..502393434 100644 --- a/modules/gui/src/sequence_viewer/secstr_row.cc +++ b/modules/gui/src/sequence_viewer/secstr_row.cc @@ -98,7 +98,7 @@ void SecStrRow::DoubleClicked(int column) if(column>0){ column-=1; const QVarLengthArray<mol::SecStructure>& sec = this->secstr_; - if(sec.size()>0 && column < sec.size()){ + if(! sec.isEmpty()>0 && column < sec.size()){ const mol::SecStructure& src_str = sec[column]; QVarLengthArray<bool> src_type(3); src_type[0] = src_str.IsHelical(); diff --git a/modules/gui/src/sequence_viewer/seq_secstr_painter.cc b/modules/gui/src/sequence_viewer/seq_secstr_painter.cc index 2fd54b35e..8d07b4dd0 100644 --- a/modules/gui/src/sequence_viewer/seq_secstr_painter.cc +++ b/modules/gui/src/sequence_viewer/seq_secstr_painter.cc @@ -38,7 +38,7 @@ void SeqSecStrPainter::Paint(QPainter* painter, const QStyleOptionViewItem& opti painter->setPen(QPen(Qt::lightGray)); const QVarLengthArray<mol::SecStructure>& sec_str = index.data(Qt::UserRole).value<QVarLengthArray<mol::SecStructure> >(); int column = index.column()-1; - if(sec_str.size()>0 && column < sec_str.size()){ + if(! sec_str.isEmpty() && column < sec_str.size()){ QSize size = index.data(Qt::UserRole+1).toSize(); mol::SecStructure sec_element = sec_str[column]; diff --git a/modules/gui/src/sequence_viewer/sequence_viewer.cc b/modules/gui/src/sequence_viewer/sequence_viewer.cc index 29314805c..85ff6ece6 100644 --- a/modules/gui/src/sequence_viewer/sequence_viewer.cc +++ b/modules/gui/src/sequence_viewer/sequence_viewer.cc @@ -315,7 +315,7 @@ void SequenceViewer::CopyEvent(QKeyEvent* event) { QItemSelectionModel* model = seq_table_view_->selectionModel(); const QModelIndexList& list = model->selectedIndexes(); - if(list.size()>0){ + if(! list.empty()){ QString clipboard_string; QSet<int> rows; int min_col=model_->columnCount(); @@ -388,7 +388,7 @@ void SequenceViewer::SelectList(const QModelIndexList& list) rows_visited.insert(row); } } - if (list.size() > 0) { + if (! list.empty()) { int last_row = 0; int last_col = 0; QModelIndex topleft_idx; diff --git a/modules/img/base/src/progress.hh b/modules/img/base/src/progress.hh index fa5e2f9e2..4af9cfc6b 100644 --- a/modules/img/base/src/progress.hh +++ b/modules/img/base/src/progress.hh @@ -43,7 +43,7 @@ public: void AdvanceProgress(const void* process,unsigned long step=1); Real GetProgress(); void AddCallback(void(*fpt)(void)){function_pointer_=fpt;} - bool IsActive(){return processes_.size()>0;} + bool IsActive(){return ! processes_.empty();} private: Progress(); Real progress_; diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index 762939ca8..12494ce3d 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -361,7 +361,7 @@ bool MMCifReader::ParseAtomIdent(const std::vector<StringRef>& columns, auth_chain_name = columns[indices_[AUTH_ASYM_ID]].str(); cif_chain_name = columns[indices_[LABEL_ASYM_ID]].str(); - if (restrict_chains_.size() > 0 && + if (! restrict_chains_.empty() && restrict_chains_.find(cif_chain_name) == String::npos) { return false; } @@ -939,7 +939,7 @@ std::vector<std::vector<String> > MMCifReader::UnPackOperExperession(StringRef e } else if (*s == ')') { StoreExpression(l, s, is_range, lborder, single_block); l = s+1; - if (single_block.size() > 0) { + if (! single_block.empty()) { unpacked.push_back(single_block); } single_block.clear(); diff --git a/modules/io/src/mol/pdb_reader.cc b/modules/io/src/mol/pdb_reader.cc index e706d960d..9f3897866 100644 --- a/modules/io/src/mol/pdb_reader.cc +++ b/modules/io/src/mol/pdb_reader.cc @@ -493,7 +493,7 @@ void PDBReader::AssignMolIds(mol::EntityHandle ent) { } } } - if (compnds_.size()>0){ + if (! compnds_.empty()){ mol::ChainHandleList ch_list=ent.GetChainList(); for (mol::ChainHandleList::const_iterator chain=ch_list.begin(); chain!=ch_list.end(); ++chain) { @@ -597,7 +597,7 @@ bool PDBReader::ParseAtomIdent(const StringRef& line, int line_num, } } else { chain_name=String(1, line[21]); - if (restrict_chains_.size()>0 && + if (! restrict_chains_.empty() && restrict_chains_.find(chain_name)==String::npos) { return false; } diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc index 3df6a4917..e54da5bae 100644 --- a/modules/io/src/mol/pdb_writer.cc +++ b/modules/io/src/mol/pdb_writer.cc @@ -117,7 +117,7 @@ void write_atom(std::ostream& ostr, FormattedLine& line, String chain_name=res.GetChain().GetName(); if (!charmm_style) { - if (chain_name.size()>0) { + if (! chain_name.empty()) { if (chain_name.size()==1) { line[21]=chain_name[0]; } else { diff --git a/modules/mol/alg/src/lddt.cc b/modules/mol/alg/src/lddt.cc index 3f7813b98..929efa9ac 100644 --- a/modules/mol/alg/src/lddt.cc +++ b/modules/mol/alg/src/lddt.cc @@ -251,7 +251,7 @@ int main (int argc, char **argv) if (!ref) { exit(-1); } - if (ref_list.size()>0) { + if (! ref_list.empty()) { if (ref_list[0].GetChainList()[0].GetName()!=ref.GetChainList()[0].GetName()) { std::cout << "ERROR: First chains in the reference structures have different names" << std::endl; exit(-1); diff --git a/modules/mol/base/src/impl/residue_impl.cc b/modules/mol/base/src/impl/residue_impl.cc index 29fee9883..3b44d844f 100644 --- a/modules/mol/base/src/impl/residue_impl.cc +++ b/modules/mol/base/src/impl/residue_impl.cc @@ -88,7 +88,7 @@ Real ResidueImpl::GetAverageBFactor() const e=atom_list_.end(); i!=e; ++i) { sum+=(*i)->GetBFactor(); } - return atom_list_.size()>0 ? sum/atom_list_.size() : 0.0; + return ! atom_list_.empty() ? sum/atom_list_.size() : 0.0; } void ResidueImpl::AddAltAtom(const String& group, const AtomImplPtr& atom, @@ -509,7 +509,7 @@ geom::AlignedCuboid ResidueImpl::GetBounds() const geom::Vec3 mmin( std::numeric_limits<Real>::infinity()); geom::Vec3 mmax(-std::numeric_limits<Real>::infinity()); - if (atom_list_.size()>0) { + if (! atom_list_.empty()) { AtomImplList::const_iterator i=atom_list_.begin(); mmin=mmax=(*i)->TransformedPos(); for (++i; i!=atom_list_.end(); ++i) { diff --git a/modules/mol/base/src/query_state.cc b/modules/mol/base/src/query_state.cc index 63a4be693..a9ba90a25 100644 --- a/modules/mol/base/src/query_state.cc +++ b/modules/mol/base/src/query_state.cc @@ -109,7 +109,7 @@ QueryState::~QueryState() QueryState::QueryState(const QueryImpl& query, const EntityHandle& ref) : q_(query) { s_.resize(query.sel_values_.size(),boost::logic::indeterminate); - if (query.bracketed_expr_.size()>0) { + if (! query.bracketed_expr_.empty()) { r_.reset(new LazilyBoundData); r_->refs.resize(query.bracketed_expr_.size()); for (size_t i=0;i<query.bracketed_expr_.size(); ++i) { @@ -127,7 +127,7 @@ LazilyBoundRef& LazilyBoundRef::operator=(const LazilyBoundRef& rhs) { QueryState::QueryState(const QueryImpl& query, const EntityView& ref) : q_(query) { s_.resize(query.sel_values_.size(),boost::logic::indeterminate); - if (query.bracketed_expr_.size()>0) { + if (! query.bracketed_expr_.empty()) { r_.reset(new LazilyBoundData); r_->refs.resize(query.bracketed_expr_.size()); for (size_t i=0;i<query.bracketed_expr_.size(); ++i) { -- GitLab