Merge "std::string_view is no longer experimental." am: c8022a3efc

am: 152d7e0f6c

Change-Id: I0a065822dccf52c28606bb13bef275c8eded46cf
This commit is contained in:
Elliott Hughes 2017-12-01 16:54:06 +00:00 committed by android-build-merger
commit 90fa16bf96
2 changed files with 14 additions and 16 deletions

View file

@ -25,9 +25,9 @@
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <experimental/string_view>
#include <functional> #include <functional>
#include <string> #include <string>
#include <string_view>
#include <unordered_map> #include <unordered_map>
#include <log/event_tag_map.h> #include <log/event_tag_map.h>
@ -44,10 +44,10 @@
class MapString { class MapString {
private: private:
const std::string* alloc; // HAS-AN const std::string* alloc; // HAS-AN
const std::experimental::string_view str; // HAS-A const std::string_view str; // HAS-A
public: public:
operator const std::experimental::string_view() const { operator const std::string_view() const {
return str; return str;
} }
@ -92,8 +92,7 @@ struct std::hash<MapString>
: public std::unary_function<const MapString&, size_t> { : public std::unary_function<const MapString&, size_t> {
size_t operator()(const MapString& __t) const noexcept { size_t operator()(const MapString& __t) const noexcept {
if (!__t.length()) return 0; if (!__t.length()) return 0;
return std::hash<std::experimental::string_view>()( return std::hash<std::string_view>()(std::string_view(__t));
std::experimental::string_view(__t));
} }
}; };

View file

@ -25,9 +25,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <algorithm> // std::max #include <algorithm> // std::max
#include <experimental/string_view>
#include <memory> #include <memory>
#include <string> // std::string #include <string>
#include <string_view>
#include <unordered_map> #include <unordered_map>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
@ -495,7 +495,7 @@ struct TagEntry : public EntryBaseDropped {
struct TagNameKey { struct TagNameKey {
std::string* alloc; std::string* alloc;
std::experimental::string_view name; // Saves space if const char* std::string_view name; // Saves space if const char*
explicit TagNameKey(const LogBufferElement* element) explicit TagNameKey(const LogBufferElement* element)
: alloc(nullptr), name("", strlen("")) { : alloc(nullptr), name("", strlen("")) {
@ -504,31 +504,31 @@ struct TagNameKey {
if (tag) { if (tag) {
const char* cp = android::tagToName(tag); const char* cp = android::tagToName(tag);
if (cp) { if (cp) {
name = std::experimental::string_view(cp, strlen(cp)); name = std::string_view(cp, strlen(cp));
return; return;
} }
} }
alloc = new std::string( alloc = new std::string(
android::base::StringPrintf("[%" PRIu32 "]", tag)); android::base::StringPrintf("[%" PRIu32 "]", tag));
if (!alloc) return; if (!alloc) return;
name = std::experimental::string_view(alloc->c_str(), alloc->size()); name = std::string_view(alloc->c_str(), alloc->size());
return; return;
} }
const char* msg = element->getMsg(); const char* msg = element->getMsg();
if (!msg) { if (!msg) {
name = std::experimental::string_view("chatty", strlen("chatty")); name = std::string_view("chatty", strlen("chatty"));
return; return;
} }
++msg; ++msg;
unsigned short len = element->getMsgLen(); unsigned short len = element->getMsgLen();
len = (len <= 1) ? 0 : strnlen(msg, len - 1); len = (len <= 1) ? 0 : strnlen(msg, len - 1);
if (!len) { if (!len) {
name = std::experimental::string_view("<NULL>", strlen("<NULL>")); name = std::string_view("<NULL>", strlen("<NULL>"));
return; return;
} }
alloc = new std::string(msg, len); alloc = new std::string(msg, len);
if (!alloc) return; if (!alloc) return;
name = std::experimental::string_view(alloc->c_str(), alloc->size()); name = std::string_view(alloc->c_str(), alloc->size());
} }
explicit TagNameKey(TagNameKey&& rval) explicit TagNameKey(TagNameKey&& rval)
@ -545,7 +545,7 @@ struct TagNameKey {
if (alloc) delete alloc; if (alloc) delete alloc;
} }
operator const std::experimental::string_view() const { operator const std::string_view() const {
return name; return name;
} }
@ -576,8 +576,7 @@ struct std::hash<TagNameKey>
: public std::unary_function<const TagNameKey&, size_t> { : public std::unary_function<const TagNameKey&, size_t> {
size_t operator()(const TagNameKey& __t) const noexcept { size_t operator()(const TagNameKey& __t) const noexcept {
if (!__t.length()) return 0; if (!__t.length()) return 0;
return std::hash<std::experimental::string_view>()( return std::hash<std::string_view>()(std::string_view(__t));
std::experimental::string_view(__t));
} }
}; };