X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fdynamic.cpp;h=7015d8b8ea9beb7cbea05bbc682b042445680e12;hb=114e32af8fd5d8e04683df4073d73e0652f09fff;hp=725cf56ad1bb0beaf90a2d38b8e24346d110af6a;hpb=178d3b45f745e50fa70c735703bfe7c4dba9ace5;p=folly.git diff --git a/folly/dynamic.cpp b/folly/dynamic.cpp index 725cf56a..7015d8b8 100644 --- a/folly/dynamic.cpp +++ b/folly/dynamic.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ #include +#include namespace folly { @@ -27,7 +28,7 @@ namespace folly { FOLLY_DYNAMIC_DEF_TYPEINFO(void*) FOLLY_DYNAMIC_DEF_TYPEINFO(bool) -FOLLY_DYNAMIC_DEF_TYPEINFO(fbstring) +FOLLY_DYNAMIC_DEF_TYPEINFO(std::string) FOLLY_DYNAMIC_DEF_TYPEINFO(dynamic::Array) FOLLY_DYNAMIC_DEF_TYPEINFO(double) FOLLY_DYNAMIC_DEF_TYPEINFO(int64_t) @@ -57,18 +58,35 @@ TypeError::~TypeError() = default; // This is a higher-order preprocessor macro to aid going from runtime // types to the compile time type system. -#define FB_DYNAMIC_APPLY(type, apply) do { \ - switch ((type)) { \ - case NULLT: apply(void*); break; \ - case ARRAY: apply(Array); break; \ - case BOOL: apply(bool); break; \ - case DOUBLE: apply(double); break; \ - case INT64: apply(int64_t); break; \ - case OBJECT: apply(ObjectImpl); break; \ - case STRING: apply(fbstring); break; \ - default: CHECK(0); abort(); \ - } \ -} while (0) +#define FB_DYNAMIC_APPLY(type, apply) \ + do { \ + switch ((type)) { \ + case NULLT: \ + apply(void*); \ + break; \ + case ARRAY: \ + apply(Array); \ + break; \ + case BOOL: \ + apply(bool); \ + break; \ + case DOUBLE: \ + apply(double); \ + break; \ + case INT64: \ + apply(int64_t); \ + break; \ + case OBJECT: \ + apply(ObjectImpl); \ + break; \ + case STRING: \ + apply(std::string); \ + break; \ + default: \ + CHECK(0); \ + abort(); \ + } \ + } while (0) bool dynamic::operator<(dynamic const& o) const { if (UNLIKELY(type_ == OBJECT || o.type_ == OBJECT)) { @@ -227,7 +245,7 @@ std::size_t dynamic::size() const { if (auto* obj = get_nothrow()) { return obj->size(); } - if (auto* str = get_nothrow()) { + if (auto* str = get_nothrow()) { return str->size(); } throw TypeError("array/object", type()); @@ -248,13 +266,16 @@ std::size_t dynamic::hash() const { case NULLT: throw TypeError("not null/object/array", type()); case INT64: - return std::hash()(asInt()); + return std::hash()(getInt()); case DOUBLE: - return std::hash()(asDouble()); + return std::hash()(getDouble()); case BOOL: - return std::hash()(asBool()); - case STRING: - return std::hash()(asString()); + return std::hash()(getBool()); + case STRING: { + // keep it compatible with FBString + const auto& str = getString(); + return ::folly::hash::fnv32_buf(str.data(), str.size()); + } default: CHECK(0); abort(); }