r21374 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21373‎ | r21374 | r21375 >
Date:13:02, 19 April 2007
Author:river
Status:old
Tags:
Comment:
solaris-gcc frag needs -m64
mkcache should use more compact data structure
Modified paths:
  • /trunk/sixdeg/frag/solaris-gcc.mk (modified) (history)
  • /trunk/sixdeg/mkcache/mkcache.cc (modified) (history)
  • /trunk/sixdeg/solaris-gcc.mk (modified) (history)

Diff [purge]

Index: trunk/sixdeg/frag/solaris-gcc.mk
@@ -1,5 +1,5 @@
22 PLAT_CPPFLAGS = -D_REENTRANT -DSOLARIS
3 -PLAT_CXXFLAGS = -O2 -g -W -Wall -Wno-non-virtual-dtor
 3+PLAT_CXXFLAGS = -O2 -g -W -Wall -Wno-non-virtual-dtor -m64
44 PLAT_LIBS = -lrt -lsocket -lnsl
55 CC = gcc
66 CXX = g++
Index: trunk/sixdeg/mkcache/mkcache.cc
@@ -93,9 +93,11 @@
9494 }
9595
9696 struct page_entry {
 97+ page_entry() : id(-1) {}
 98+ page_id_t id;
9799 text_id_t text;
98100 std::string name;
99 - std::set<page_id_t> adj;
 101+ std::vector<page_id_t> adj;
100102 };
101103
102104 void
@@ -115,7 +117,8 @@
116118 * First we cache the data for this wiki in RAM, then commit all once.
117119 * This avoids constantly (over)writing in the database.
118120 */
119 - std::map<page_id_t, page_entry> cache;
 121+ //std::map<page_id_t, page_entry> cache;
 122+ std::vector<page_entry> cache;
120123 MYSQL_ROW arow;
121124 int i = 0;
122125 std::cout << db << ": 0" << std::flush;
@@ -125,24 +128,27 @@
126129
127130 page_id_t from = boost::lexical_cast<page_id_t>(arow[1]);
128131 page_id_t to = boost::lexical_cast<page_id_t>(arow[0]);
129 - std::map<page_id_t, page_entry>::iterator it = cache.find(from);
130 - if (it == cache.end()) {
131 - page_entry e;
132 - e.name = arow[2];
133 - e.text = boost::lexical_cast<text_id_t>(arow[3]);
134 - it = cache.insert(std::make_pair(from, e)).first;
 132+
 133+ if (cache.size() <= from)
 134+ cache.resize(from + 1);
 135+
 136+ if (cache[from].id == -1) {
 137+ cache[from].id = from;
 138+ cache[from].name = arow[2];
 139+ cache[from].text = boost::lexical_cast<text_id_t>(arow[3]);
135140 }
136141
137 - it->second.adj.insert(to);
 142+ cache[from].adj.push_back(to);
138143 }
139144 mysql_free_result(res);
140145
141146 bdb_adjacency_transaction *trans = new bdb_adjacency_transaction(store);
142147 std::cout << " flush to storage... " << std::flush;
143148 i = 0;
144 - for (std::map<page_id_t, page_entry>::iterator
145 - it = cache.begin(), end = cache.end();
146 - it != end; ++it) {
 149+ for (std::size_t s = 0, end = cache.size(); s < end; ++s) {
 150+ if (cache[s].id == -1)
 151+ continue;
 152+
147153 if (++i == 10000) {
148154 trans->commit();
149155 delete trans;
@@ -151,8 +157,9 @@
152158 i = 0;
153159 }
154160
155 - trans->add_title(db, it->first, it->second.name, it->second.text);
156 - trans->set_adjacencies(db, it->first, it->second.adj);
 161+ std::set<page_id_t> adj(cache[s].adj.begin(), cache[s].adj.end());
 162+ trans->add_title(db, cache[s].id, cache[s].name, cache[s].text);
 163+ trans->set_adjacencies(db, cache[s].id, adj);
157164 }
158165 trans->commit();
159166 delete trans;
Index: trunk/sixdeg/solaris-gcc.mk
@@ -1,2 +1,2 @@
2 -PLAT_FRAG = solaris.mk
 2+PLAT_FRAG = solaris-gcc.mk
33 include frag/setup.mk