From 34bfa1c23cfdc1e5aadcb3af240daea423caf31c Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 11 Feb 2011 00:55:50 +0000 Subject: Less copying and more native storage in fileRows --- project2/fileRows.cpp | 32 ++++++++++++++++---------------- project2/fileRows.h | 7 +++---- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp index 78a61a5..4a3c58b 100644 --- a/project2/fileRows.cpp +++ b/project2/fileRows.cpp @@ -20,7 +20,7 @@ FileRows::FileRows(const xmlpp::Element * p) : BOOST_FOREACH(const xmlpp::Node * node, p->find("columns/column")) { const xmlpp::Element * elem = dynamic_cast(node); if (elem) { - columns.push_back(elem->get_child_text()->get_content()); + columns.push_back(boost::shared_ptr(new Glib::ustring(elem->get_child_text()->get_content()))); } } } @@ -49,7 +49,7 @@ FileRows::columnCount() const const Glib::ustring & FileRows::getColumnName(unsigned int col) const { - return columns[col]; + return *columns[col]; } void @@ -68,11 +68,12 @@ FileRows::execute(const RowProcessor * rp) const bool mkCols = columns.empty(); bool inQuotes = false; bool prevWasQuote = false; - Glib::ustring tok; + typedef boost::shared_ptr StringPtr; + StringPtr tok(new Glib::ustring()); BOOST_FOREACH(gunichar c, line) { if (c == quoteChar) { if (prevWasQuote) { - tok += c; + *tok += c; prevWasQuote = false; inQuotes = !inQuotes; } @@ -87,29 +88,29 @@ FileRows::execute(const RowProcessor * rp) const addColumn(tok); } else { - values.push_back(ValPtr(new Glib::ustring(tok))); + values.push_back(tok); curCol++; } - tok.clear(); + tok = StringPtr(new Glib::ustring()); } else { prevWasQuote = false; - tok += c; + *tok += c; } } - if (tok.length()) { + if (tok->length()) { if (mkCols) { addColumn(tok); } else { - values.push_back(ValPtr(new Glib::ustring(tok))); + values.push_back(tok); curCol++; } } if (!mkCols) { if (keepBlankRows || !values.empty()) { while (values.size() < columns.size()) { - values.push_back(ValPtr(new Glib::ustring())); + values.push_back(VariableType()); curCol++; } rp->rowReady(); @@ -146,7 +147,7 @@ FileRows::getCurrentValue(const Glib::ustring & id) const { Values::const_iterator v = values.begin(); for (Columns::const_iterator i = columns.begin(); i != columns.end(); i++, v++) { - if (*i == id) { + if (**i == id) { return *v; } } @@ -154,13 +155,12 @@ FileRows::getCurrentValue(const Glib::ustring & id) const } void -FileRows::addColumn(const Glib::ustring & rawtok) const +FileRows::addColumn(boost::shared_ptr tok) const { - columns.push_back(rawtok); - Glib::ustring & tok(columns.back()); - for (Glib::ustring::iterator i = tok.begin(); i != tok.end(); ) { + columns.push_back(tok); + for (Glib::ustring::iterator i = tok->begin(); i != tok->end(); ) { if (!isalnum(*i)) { - tok.erase(i); + tok->erase(i); } else { i++; diff --git a/project2/fileRows.h b/project2/fileRows.h index 1edff0b..1a4b7ed 100644 --- a/project2/fileRows.h +++ b/project2/fileRows.h @@ -31,9 +31,8 @@ class FileRows : public RowSet { protected: virtual FileStarChannel doOpen() const; - void addColumn(const Glib::ustring & rawtok) const; - typedef boost::shared_ptr ValPtr; - typedef std::vector Values; + void addColumn(boost::shared_ptr rawtok) const; + typedef std::vector Values; mutable Values values; private: @@ -43,7 +42,7 @@ class FileRows : public RowSet { bool countBlankRows; std::string newline; std::string encoding; - typedef std::vector Columns; + typedef std::vector > Columns; mutable Columns columns; }; -- cgit v1.2.3