# # # patch "ChangeLog" # from [ac47679a358a459a5f5e2c38a5ba2a2c049426a8] # to [55c5c1c40c224075d4e447c08a91fd7bdce1e593] # # patch "automate.cc" # from [a8b515148a3944e116f97c4d084f8bdd5e5b5eaf] # to [97e0164b6a47a27372a76e9e7b90c6d75c006462] # # patch "basic_io.cc" # from [f648969974baf376d08f017aeb7497eaf18f4dd5] # to [dd67a9179add62505ba6388e4137d9407e1cf3dd] # # patch "basic_io.hh" # from [3fcd38cda8209ef44ed5797d7e0c64ba714cc460] # to [7199964d5427709350a247c326a78686fbc09fa8] # # patch "cset.cc" # from [5fdac8f01ad19e4a427e40aa4245026b534422f7] # to [016b2c48f116024d85578b3abc068b15eebe234a] # # patch "revision.cc" # from [dc9d63065b1efd2f3c53da2f6d19a685174e450d] # to [5949a0586ccb05cffd7ca576810d2aa51790bc5f] # # patch "roster.cc" # from [66eda9b3b3bb115886e6b0e3cbb5bc20c034ee47] # to [5165b5be5f975f2b3b03aca359dfa21ba71462fa] # # patch "work.cc" # from [f298a32c9e1d5aafa207df089207087e40133272] # to [4108481b8454d5993cbe2a1ff28d3e39bd664939] # # patch "xdelta.cc" # from [623dce88e91af3d9f610b47d7596408fa4876dda] # to [c71201cbb734ac9f92ac4d9cef4cfc53ea20f473] # ============================================================ --- ChangeLog ac47679a358a459a5f5e2c38a5ba2a2c049426a8 +++ ChangeLog 55c5c1c40c224075d4e447c08a91fd7bdce1e593 @@ -1,5 +1,11 @@ 2006-03-05 Graydon Hoare + * basic_io.{cc,hh}: Change printer to use static string buf. + * {automate,cset,revision,roster,work}.cc: Update to match. + * xdelta.cc: Minor optimizations. + +2006-03-05 Graydon Hoare + * lru_cache.h: New file. * AUTHORS: Mention Patrick. * Makefile.am: Include file. ============================================================ --- automate.cc a8b515148a3944e116f97c4d084f8bdd5e5b5eaf +++ automate.cc 97e0164b6a47a27372a76e9e7b90c6d75c006462 @@ -844,7 +844,7 @@ // particular. std::sort(certs.begin(), certs.end()); - basic_io::printer pr(output); + basic_io::printer pr; for (size_t i = 0; i < certs.size(); ++i) { @@ -885,6 +885,7 @@ pr.print_stanza(st); } + output.write(pr.buf.data(), pr.buf.size()); guard.commit(); } @@ -1466,7 +1467,7 @@ items[(*i)()].get<2>().push_back("keystore"); items[(*i)()].get<3>().push_back("keystore"); } - basic_io::printer prt(output); + basic_io::printer prt; for (std::map, hexenc, std::vector, std::vector > >::iterator @@ -1482,6 +1483,7 @@ stz.push_str_multi("private_location", i->second.get<3>()); prt.print_stanza(stz); } + output.write(prt.buf.data(), prt.buf.size()); } ============================================================ --- basic_io.cc f648969974baf376d08f017aeb7497eaf18f4dd5 +++ basic_io.cc dd67a9179add62505ba6388e4137d9407e1cf3dd @@ -34,7 +34,8 @@ in.err(s); } -std::string basic_io::escape(std::string const & s) +std::string +basic_io::escape(std::string const & s) { std::string escaped; escaped.reserve(s.size() + 8); @@ -138,26 +139,27 @@ } -basic_io::printer::printer(std::ostream & ost) - : empty_output(true), out(ost) -{} +std::string basic_io::printer::buf; +basic_io::printer::printer() +{ + buf.clear(); +} + void basic_io::printer::print_stanza(stanza const & st) { - if (empty_output) - empty_output = false; - else - out.put('\n'); - + if (LIKELY(!buf.empty())) + buf += '\n'; + for (std::vector >::const_iterator i = st.entries.begin(); i != st.entries.end(); ++i) { for (size_t k = i->first.size(); k < st.indent; ++k) - out.put(' '); - out.write(i->first.data(), i->first.size()); - out.put(' '); - out.write(i->second.data(), i->second.size()); - out.put('\n'); + buf += ' '; + buf.append(i->first); + buf += ' '; + buf.append(i->second); + buf += '\n'; } } ============================================================ --- basic_io.hh 3fcd38cda8209ef44ed5797d7e0c64ba714cc460 +++ basic_io.hh 7199964d5427709350a247c326a78686fbc09fa8 @@ -261,9 +261,8 @@ struct printer { - bool empty_output; - std::ostream & out; - printer(std::ostream & ost); + static std::string buf; + printer(); void print_stanza(stanza const & st); }; ============================================================ --- cset.cc 5fdac8f01ad19e4a427e40aa4245026b534422f7 +++ cset.cc 016b2c48f116024d85578b3abc068b15eebe234a @@ -445,10 +445,9 @@ void write_cset(cset const & cs, data & dat) { - std::ostringstream oss; - basic_io::printer pr(oss); + basic_io::printer pr; print_cset(pr, cs); - dat = data(oss.str()); + dat = data(pr.buf); } void ============================================================ --- revision.cc dc9d63065b1efd2f3c53da2f6d19a685174e450d +++ revision.cc 5949a0586ccb05cffd7ca576810d2aa51790bc5f @@ -1563,10 +1563,9 @@ static void write_insane_revision_set(revision_set const & rev, data & dat) { - std::ostringstream oss; - basic_io::printer pr(oss); + basic_io::printer pr; print_revision(pr, rev); - dat = data(oss.str()); + dat = data(pr.buf); } template <> void ============================================================ --- roster.cc 66eda9b3b3bb115886e6b0e3cbb5bc20c034ee47 +++ roster.cc 5165b5be5f975f2b3b03aca359dfa21ba71462fa @@ -2431,10 +2431,9 @@ ros.check_sane_against(mm); else ros.check_sane(true); - std::ostringstream oss; - basic_io::printer pr(oss); + basic_io::printer pr; ros.print_to(pr, mm, print_local_parts); - dat = data(oss.str()); + dat = data(pr.buf); } ============================================================ --- work.cc f298a32c9e1d5aafa207df089207087e40133272 +++ work.cc 4108481b8454d5993cbe2a1ff28d3e39bd664939 @@ -681,8 +681,7 @@ void write_options_map(data & dat, options_map const & options) { - std::ostringstream oss; - basic_io::printer pr(oss); + basic_io::printer pr; basic_io::stanza st; for (options_map::const_iterator i = options.begin(); @@ -690,7 +689,7 @@ st.push_str_pair(i->first, i->second()); pr.print_stanza(st); - dat = oss.str(); + dat = pr.buf; } // local dump file ============================================================ --- xdelta.cc 623dce88e91af3d9f610b47d7596408fa4876dda +++ xdelta.cc c71201cbb734ac9f92ac4d9cef4cfc53ea20f473 @@ -112,20 +112,25 @@ return false; apos = tpos; - alen = tlen; - badvance = tlen; // see if we can extend our match forwards - while((apos + alen >= 0) - && (bpos + badvance >= 0) - && (apos + alen < a.size()) - && (bpos + badvance < b.size()) - && (a[apos + alen] == b[bpos + badvance])) + string::const_iterator ai = a.begin() + apos + tlen; + string::const_iterator ae = a.end(); + string::const_iterator bi = b.begin() + bpos + tlen; + string::const_iterator be = b.end(); + + while((*ai == *bi) + && (ai != ae) + && (bi != be)) { - ++alen; - ++badvance; + ++tlen; + ++ai; + ++bi; } + alen = tlen; + badvance = tlen; + // see if we can extend backwards into a previous insert hunk if (! delta.empty() && delta.back().code == insn::insert) {