Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/sync/util/fast_dump.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_
6 #define CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_
7
8 #include <ostream>
9 #include <streambuf>
10 #include <string>
11
12 #include "base/string_util.h"
13
14 using std::ostream;
15 using std::streambuf;
16 using std::string;
17
18 // This seems totally gratuitous, and it would be if std::ostream was fast, but
19 // std::ostream is slow. It's slow because it creates a ostream::sentry (mutex)
20 // for every little << operator. When you want to dump a whole lot of stuff
21 // under a single mutex lock, use this FastDump class.
22 namespace browser_sync {
23 class FastDump {
24 public:
25 explicit FastDump(ostream* outs) : sentry_(*outs), out_(outs->rdbuf()) {
26 }
27 ostream::sentry sentry_;
28 streambuf* const out_;
29 };
30 } // namespace browser_sync
31
32 inline browser_sync::FastDump& operator <<
33 (browser_sync::FastDump& dump, int64 n) {
34 string numbuf(Int64ToString(n));
35 const char* number = numbuf.c_str();
36 dump.out_->sputn(number, numbuf.length());
37 return dump;
38 }
39
40 inline browser_sync::FastDump& operator <<
41 (browser_sync::FastDump& dump, int32 n) {
42 string numbuf(IntToString(n));
43 const char* number = numbuf.c_str();
44 dump.out_->sputn(number, numbuf.length());
45 return dump;
46 }
47
48 inline browser_sync::FastDump& operator <<
49 (browser_sync::FastDump& dump, const char* s) {
50 dump.out_->sputn(s, strlen(s));
51 return dump;
52 }
53
54 inline browser_sync::FastDump& operator <<
55 (browser_sync::FastDump& dump, const string& s) {
56 dump.out_->sputn(s.data(), s.size());
57 return dump;
58 }
59
60 #endif // CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698