8000 dynamic.h operator== claiming to do a deep equal comparison but its not · Issue #2424 · facebook/folly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
dynamic.h operator== claiming to do a deep equal comparison but its not #2424
Open
@hannojg

Description

@hannojg

In the json/dynamic.h its saying that the equal operator will do a deep equal comparison:

folly/folly/json/dynamic.h

Lines 293 to 301 in 08d6d55

/**
* Deep equality comparison. This will compare all the way down
* an object or array, and is potentially expensive.
*
* NOTE: Implicit conversion will be done between ints and doubles, so numeric
* equality will apply between those cases. Other dynamic value comparisons of
* different types will always return false.
*/
friend bool operator==(dynamic const& a, dynamic const& b);

but looking into the implementation if the types are matching its just comparing the address:

bool operator==(dynamic const& a, dynamic const& b) {
if (a.type() != b.type()) {
if (a.isNumber() && b.isNumber()) {
auto& integ = a.isInt() ? a : b;
auto& doubl = a.isInt() ? b : a;
return integ.asInt() == doubl.asDouble();
}
return false;
}
#define FB_X(T) return *a.getAddress<T>() == *b.getAddress<T>();
FB_DYNAMIC_APPLY(a.type_, FB_X);
#undef FB_X

Maybe I am missing something but it seems to me that his is incorrect and no actual deep equal comparison? (I am looking for a built-in way to do a deep equal compare)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0