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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hannojg opened this issue Apr 24, 2025 · 1 comment
Open

Comments

@hannojg
Copy link
hannojg commented Apr 24, 2025

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)

@yfeldblum
Copy link
Contributor

This doesn't look like it compares addresses. *a.getAddress<T> is T&, not T*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0