OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_ | 5 #ifndef CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_ |
6 #define CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_ | 6 #define CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <ostream> | 9 #include <ostream> |
10 #include <streambuf> | 10 #include <streambuf> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/string_util.h" | 13 #include "base/string_number_conversions.h" |
14 | 14 |
15 using std::ostream; | 15 using std::ostream; |
16 using std::streambuf; | 16 using std::streambuf; |
17 using std::string; | 17 using std::string; |
18 | 18 |
19 // This seems totally gratuitous, and it would be if std::ostream was fast, but | 19 // This seems totally gratuitous, and it would be if std::ostream was fast, but |
20 // std::ostream is slow. It's slow because it creates a ostream::sentry (mutex) | 20 // std::ostream is slow. It's slow because it creates a ostream::sentry (mutex) |
21 // for every little << operator. When you want to dump a whole lot of stuff | 21 // for every little << operator. When you want to dump a whole lot of stuff |
22 // under a single mutex lock, use this FastDump class. | 22 // under a single mutex lock, use this FastDump class. |
23 namespace browser_sync { | 23 namespace browser_sync { |
24 class FastDump { | 24 class FastDump { |
25 public: | 25 public: |
26 explicit FastDump(ostream* outs) : sentry_(*outs), out_(outs->rdbuf()) { | 26 explicit FastDump(ostream* outs) : sentry_(*outs), out_(outs->rdbuf()) { |
27 } | 27 } |
28 ostream::sentry sentry_; | 28 ostream::sentry sentry_; |
29 streambuf* const out_; | 29 streambuf* const out_; |
30 }; | 30 }; |
31 } // namespace browser_sync | 31 } // namespace browser_sync |
32 | 32 |
33 inline browser_sync::FastDump& operator << | 33 inline browser_sync::FastDump& operator << |
34 (browser_sync::FastDump& dump, int64 n) { | 34 (browser_sync::FastDump& dump, int64 n) { |
35 string numbuf(Int64ToString(n)); | 35 string numbuf(base::Int64ToString(n)); |
36 const char* number = numbuf.c_str(); | 36 const char* number = numbuf.c_str(); |
37 dump.out_->sputn(number, numbuf.length()); | 37 dump.out_->sputn(number, numbuf.length()); |
38 return dump; | 38 return dump; |
39 } | 39 } |
40 | 40 |
41 inline browser_sync::FastDump& operator << | 41 inline browser_sync::FastDump& operator << |
42 (browser_sync::FastDump& dump, int32 n) { | 42 (browser_sync::FastDump& dump, int32 n) { |
43 string numbuf(IntToString(n)); | 43 string numbuf(base::IntToString(n)); |
44 const char* number = numbuf.c_str(); | 44 const char* number = numbuf.c_str(); |
45 dump.out_->sputn(number, numbuf.length()); | 45 dump.out_->sputn(number, numbuf.length()); |
46 return dump; | 46 return dump; |
47 } | 47 } |
48 | 48 |
49 inline browser_sync::FastDump& operator << | 49 inline browser_sync::FastDump& operator << |
50 (browser_sync::FastDump& dump, const char* s) { | 50 (browser_sync::FastDump& dump, const char* s) { |
51 dump.out_->sputn(s, strlen(s)); | 51 dump.out_->sputn(s, strlen(s)); |
52 return dump; | 52 return dump; |
53 } | 53 } |
54 | 54 |
55 inline browser_sync::FastDump& operator << | 55 inline browser_sync::FastDump& operator << |
56 (browser_sync::FastDump& dump, const string& s) { | 56 (browser_sync::FastDump& dump, const string& s) { |
57 dump.out_->sputn(s.data(), s.size()); | 57 dump.out_->sputn(s.data(), s.size()); |
58 return dump; | 58 return dump; |
59 } | 59 } |
60 | 60 |
61 #endif // CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_ | 61 #endif // CHROME_BROWSER_SYNC_UTIL_FAST_DUMP_H_ |
OLD | NEW |