From 583affbef7cb0cb8c41b1cb55c7a076af7feee67 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Fri, 27 May 2016 13:38:20 -0700 Subject: [PATCH] remove FunctionComparator --- src/RealmJS.xcodeproj/project.pbxproj | 2 -- src/js_list.hpp | 2 +- src/js_results.hpp | 6 ++--- src/js_types.hpp | 7 +----- src/jsc/jsc_init.hpp | 1 - src/jsc/jsc_notification_map.hpp | 34 --------------------------- src/jsc/jsc_protected.hpp | 10 ++++++++ 7 files changed, 15 insertions(+), 47 deletions(-) delete mode 100644 src/jsc/jsc_notification_map.hpp diff --git a/src/RealmJS.xcodeproj/project.pbxproj b/src/RealmJS.xcodeproj/project.pbxproj index ad0ca3b4..844b823d 100644 --- a/src/RealmJS.xcodeproj/project.pbxproj +++ b/src/RealmJS.xcodeproj/project.pbxproj @@ -98,7 +98,6 @@ 02414B9F1CE6AAEF00A8669F /* results_notifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = results_notifier.cpp; path = src/impl/results_notifier.cpp; sourceTree = ""; }; 02414BA01CE6AAEF00A8669F /* results_notifier.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = results_notifier.hpp; path = src/impl/results_notifier.hpp; sourceTree = ""; }; 025678951CAB392000FB8501 /* jsc_types.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsc_types.hpp; sourceTree = ""; }; - 026D72111CF8B23C00EF1DCC /* jsc_notification_map.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsc_notification_map.hpp; sourceTree = ""; }; 0270BC5A1B7CFC1300010E03 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 0270BC781B7D020100010E03 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = ""; }; 0270BC7A1B7D020100010E03 /* RealmJSTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmJSTests.h; path = ios/RealmJSTests.h; sourceTree = ""; }; @@ -508,7 +507,6 @@ F60103081CC4B4F900EC01BA /* jsc_protected.hpp */, F60103141CC4CC8C00EC01BA /* jsc_return_value.hpp */, F60102E71CBBB36500EC01BA /* jsc_object_accessor.hpp */, - 026D72111CF8B23C00EF1DCC /* jsc_notification_map.hpp */, ); name = JSC; path = jsc; diff --git a/src/js_list.hpp b/src/js_list.hpp index 5b24648d..752236a1 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -38,7 +38,7 @@ class List : public realm::List { List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l) noexcept : realm::List(r, s, l) {} List(const realm::List &l) : realm::List(l) {} - std::map::ComparableFunction, NotificationToken, FunctionComparator> m_notification_tokens; + std::map, NotificationToken, Protected> m_notification_tokens; }; template diff --git a/src/js_results.hpp b/src/js_results.hpp index 9bf60351..87876e78 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -32,7 +32,7 @@ namespace js { template class Results : public realm::Results { public: - Results(Results const&) : realm::Results(*this) {}; + Results(Results const& r) : realm::Results(r) {}; Results(Results&&) = default; Results& operator=(Results&&) = default; Results& operator=(Results const&) = default; @@ -43,7 +43,7 @@ class Results : public realm::Results { Results(SharedRealm r, const ObjectSchema& o, TableView tv, SortOrder s) : realm::Results(r, o, tv, s) {} Results(SharedRealm r, const ObjectSchema& o, LinkViewRef lv, util::Optional q = {}, SortOrder s = {}) : realm::Results(r, o, lv, q, s) {} - std::map::ComparableFunction, NotificationToken, FunctionComparator> m_notification_tokens; + std::map, NotificationToken, Protected> m_notification_tokens; }; template @@ -282,7 +282,7 @@ void ResultsClass::add_listener(ContextType ctx, ObjectType this_object, size arguments[1] = CollectionClass::create_collection_change_set(protected_ctx, change_set); Function::call(protected_ctx, protected_callback, protected_this, 2, arguments); }); - results->m_notification_tokens.emplace(std::make_pair(protected_ctx, protected_callback), std::move(token)); + results->m_notification_tokens.emplace(protected_callback, std::move(token)); } template diff --git a/src/js_types.hpp b/src/js_types.hpp index 2e797c80..b70b8f84 100644 --- a/src/js_types.hpp +++ b/src/js_types.hpp @@ -247,6 +247,7 @@ class Protected { bool operator!=(const ValueType &) const; bool operator==(const Protected &) const; bool operator!=(const Protected &) const; + bool operator()(const Protected& a, const Protected& b) const; }; template @@ -288,12 +289,6 @@ struct ReturnValue { void set_null(); void set_undefined(); }; - -template -struct FunctionComparator { - using ComparableFunction = std::pair, Protected>; - bool operator()(const ComparableFunction& a, const ComparableFunction& b) const; -}; template REALM_JS_INLINE typename T::Object create_object(typename T::Context ctx, typename ClassType::Internal* internal = nullptr) { diff --git a/src/jsc/jsc_init.hpp b/src/jsc/jsc_init.hpp index e2629534..de19d7b9 100644 --- a/src/jsc/jsc_init.hpp +++ b/src/jsc/jsc_init.hpp @@ -28,6 +28,5 @@ #include "jsc_exception.hpp" #include "jsc_return_value.hpp" #include "jsc_object_accessor.hpp" -#include "jsc_notification_map.hpp" #include "js_realm.hpp" diff --git a/src/jsc/jsc_notification_map.hpp b/src/jsc/jsc_notification_map.hpp deleted file mode 100644 index fbd8c3b0..00000000 --- a/src/jsc/jsc_notification_map.hpp +++ /dev/null @@ -1,34 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2016 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include "jsc_types.hpp" - -namespace realm { -namespace js { - -template<> -bool FunctionComparator::operator()(const ComparableFunction& a, const ComparableFunction& b) const { - if ((JSGlobalContextRef)a.first != (JSGlobalContextRef)b.first) { - return false; - } - return JSValueIsStrictEqual(a.first, a.second, b.second); -} - -}} diff --git a/src/jsc/jsc_protected.hpp b/src/jsc/jsc_protected.hpp index 6c20d039..f3aa87ee 100644 --- a/src/jsc/jsc_protected.hpp +++ b/src/jsc/jsc_protected.hpp @@ -47,6 +47,10 @@ class Protected { operator bool() const { return m_context != nullptr; } + + bool operator() (const Protected& a, const Protected& b) const { + return a.m_context == b.m_context; + } }; template<> @@ -75,6 +79,12 @@ class Protected { operator bool() const { return m_value != nullptr; } + bool operator() (const Protected& a, const Protected& b) const { + if (a.m_context != b.m_context) { + return false; + } + return JSValueIsStrictEqual(a.m_context, a.m_value, b.m_value); + } }; template<>