| 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 const ::std::string* empty_string_; | 51 ExplicitlyConstructed< ::std::string> fixed_address_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() { | 54 void DeleteEmptyString() { |
| 55 delete empty_string_; | 55 GetEmptyStringAlreadyInited().~string(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void InitEmptyString() { | 58 void InitEmptyString() { |
| 59 empty_string_ = new string; | 59 fixed_address_empty_string.DefaultConstruct(); |
| 60 OnShutdown(&DeleteEmptyString); | 60 OnShutdown(&DeleteEmptyString); |
| 61 } | 61 } |
| 62 | 62 |
| 63 const ::std::string& GetEmptyStringAlreadyInited() { |
| 64 return fixed_address_empty_string.get(); |
| 65 } |
| 66 |
| 63 const ::std::string& GetEmptyString() { | 67 const ::std::string& GetEmptyString() { |
| 64 ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString)
; | 68 ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString)
; |
| 65 return GetEmptyStringAlreadyInited(); | 69 return GetEmptyStringAlreadyInited(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 | |
| 69 int StringSpaceUsedExcludingSelf(const string& str) { | 72 int StringSpaceUsedExcludingSelf(const string& str) { |
| 70 const void* start = &str; | 73 const void* start = &str; |
| 71 const void* end = &str + 1; | 74 const void* end = &str + 1; |
| 72 if (start <= str.data() && str.data() < end) { | 75 if (start <= str.data() && str.data() < end) { |
| 73 // The string's data is stored inside the string object itself. | 76 // The string's data is stored inside the string object itself. |
| 74 return 0; | 77 return 0; |
| 75 } else { | 78 } else { |
| 76 return str.capacity(); | 79 return str.capacity(); |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 80 | 83 |
| 81 | 84 |
| 85 void MergeFromFail(const char* file, int line) { |
| 86 GOOGLE_CHECK(false) << file << ":" << line; |
| 87 // Open-source GOOGLE_CHECK(false) is not NORETURN. |
| 88 exit(1); |
| 89 } |
| 90 |
| 82 } // namespace internal | 91 } // namespace internal |
| 83 } // namespace protobuf | 92 } // namespace protobuf |
| 84 } // namespace google | 93 } // namespace google |
| OLD | NEW |