OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 30 matching lines...) Expand all Loading... |
41 namespace protobuf { | 41 namespace protobuf { |
42 namespace internal { | 42 namespace internal { |
43 | 43 |
44 double Infinity() { | 44 double Infinity() { |
45 return std::numeric_limits<double>::infinity(); | 45 return std::numeric_limits<double>::infinity(); |
46 } | 46 } |
47 double NaN() { | 47 double NaN() { |
48 return std::numeric_limits<double>::quiet_NaN(); | 48 return std::numeric_limits<double>::quiet_NaN(); |
49 } | 49 } |
50 | 50 |
51 ExplicitlyConstructed< ::std::string> fixed_address_empty_string; | 51 const ::std::string* empty_string_; |
52 GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_); | 52 GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_); |
53 | 53 |
54 void DeleteEmptyString() { fixed_address_empty_string.Shutdown(); } | 54 void DeleteEmptyString() { |
| 55 delete empty_string_; |
| 56 } |
55 | 57 |
56 void InitEmptyString() { | 58 void InitEmptyString() { |
57 fixed_address_empty_string.DefaultConstruct(); | 59 empty_string_ = new string; |
58 OnShutdown(&DeleteEmptyString); | 60 OnShutdown(&DeleteEmptyString); |
59 } | 61 } |
60 | 62 |
61 const ::std::string& GetEmptyString() { | 63 const ::std::string& GetEmptyString() { |
62 ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString)
; | 64 ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString)
; |
63 return GetEmptyStringAlreadyInited(); | 65 return GetEmptyStringAlreadyInited(); |
64 } | 66 } |
65 | 67 |
66 | 68 |
67 int StringSpaceUsedExcludingSelf(const string& str) { | 69 int StringSpaceUsedExcludingSelf(const string& str) { |
68 const void* start = &str; | 70 const void* start = &str; |
69 const void* end = &str + 1; | 71 const void* end = &str + 1; |
70 if (start <= str.data() && str.data() < end) { | 72 if (start <= str.data() && str.data() < end) { |
71 // The string's data is stored inside the string object itself. | 73 // The string's data is stored inside the string object itself. |
72 return 0; | 74 return 0; |
73 } else { | 75 } else { |
74 return str.capacity(); | 76 return str.capacity(); |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 | 80 |
79 | 81 |
80 void InitProtobufDefaults() { | |
81 GetEmptyString(); | |
82 } | |
83 | |
84 } // namespace internal | 82 } // namespace internal |
85 } // namespace protobuf | 83 } // namespace protobuf |
86 } // namespace google | 84 } // namespace google |
OLD | NEW |