From c708ae8eb56eccf1f0eba1bd1dc39da1b5cd034f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 May 2016 15:51:22 +0900 Subject: [PATCH] Remove IDWeakMap --- atom/browser/api/trackable_object.h | 15 ++++++++++----- atom/common/api/atom_api_id_weak_map.h | 4 ++-- atom/common/id_weak_map.cc | 25 ------------------------- atom/common/id_weak_map.h | 33 --------------------------------- filenames.gypi | 2 -- 5 files changed, 12 insertions(+), 67 deletions(-) delete mode 100644 atom/common/id_weak_map.cc delete mode 100644 atom/common/id_weak_map.h diff --git a/atom/browser/api/trackable_object.h b/atom/browser/api/trackable_object.h index 1c71d84..2786261 100644 --- a/atom/browser/api/trackable_object.h +++ b/atom/browser/api/trackable_object.h @@ -8,7 +8,7 @@ #include #include "atom/browser/api/event_emitter.h" -#include "atom/common/id_weak_map.h" +#include "atom/common/key_weak_map.h" #include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" @@ -113,21 +113,26 @@ class TrackableObject : public TrackableObjectBase, void AfterInit(v8::Isolate* isolate) override { if (!weak_map_) { - weak_map_.reset(new atom::IDWeakMap); + weak_map_.reset(new atom::KeyWeakMap); } - weak_map_id_ = weak_map_->Add(isolate, Wrappable::GetWrapper()); + weak_map_id_ = ++next_id_; + weak_map_->Set(isolate, weak_map_id_, Wrappable::GetWrapper()); if (wrapped_) AttachAsUserData(wrapped_); } private: - static scoped_ptr weak_map_; + static int32_t next_id_; + static scoped_ptr> weak_map_; DISALLOW_COPY_AND_ASSIGN(TrackableObject); }; template -scoped_ptr TrackableObject::weak_map_; +int32_t TrackableObject::next_id_ = 0; + +template +scoped_ptr> TrackableObject::weak_map_; } // namespace mate diff --git a/atom/common/api/atom_api_id_weak_map.h b/atom/common/api/atom_api_id_weak_map.h index 0151c7c..16012b4 100644 --- a/atom/common/api/atom_api_id_weak_map.h +++ b/atom/common/api/atom_api_id_weak_map.h @@ -5,7 +5,7 @@ #ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_ #define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_ -#include "atom/common/id_weak_map.h" +#include "atom/common/key_weak_map.h" #include "native_mate/object_template_builder.h" #include "native_mate/handle.h" @@ -31,7 +31,7 @@ class IDWeakMap : public mate::Wrappable { bool Has(int32_t id); void Remove(int32_t id); - atom::IDWeakMap id_weak_map_; + atom::KeyWeakMap id_weak_map_; DISALLOW_COPY_AND_ASSIGN(IDWeakMap); }; diff --git a/atom/common/id_weak_map.cc b/atom/common/id_weak_map.cc deleted file mode 100644 index 9c14c99..0000000 --- a/atom/common/id_weak_map.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "atom/common/id_weak_map.h" - -namespace atom { - -IDWeakMap::IDWeakMap() : next_id_(0) { -} - -IDWeakMap::~IDWeakMap() { -} - -int32_t IDWeakMap::Add(v8::Isolate* isolate, v8::Local object) { - int32_t id = GetNextID(); - Set(isolate, id, object); - return id; -} - -int32_t IDWeakMap::GetNextID() { - return ++next_id_; -} - -} // namespace atom diff --git a/atom/common/id_weak_map.h b/atom/common/id_weak_map.h deleted file mode 100644 index c5cf89b..0000000 --- a/atom/common/id_weak_map.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_COMMON_ID_WEAK_MAP_H_ -#define ATOM_COMMON_ID_WEAK_MAP_H_ - -#include "atom/common/key_weak_map.h" - -namespace atom { - -// Provides key increments service in addition to KeyWeakMap. -class IDWeakMap : public KeyWeakMap { - public: - IDWeakMap(); - ~IDWeakMap() override; - - // Adds |object| to WeakMap and returns its allocated |id|. - int32_t Add(v8::Isolate* isolate, v8::Local object); - - private: - // Returns next available ID. - int32_t GetNextID(); - - // ID of next stored object. - int32_t next_id_; - - DISALLOW_COPY_AND_ASSIGN(IDWeakMap); -}; - -} // namespace atom - -#endif // ATOM_COMMON_ID_WEAK_MAP_H_ diff --git a/filenames.gypi b/filenames.gypi index 49832f4..fa1b1d7 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -338,8 +338,6 @@ 'atom/common/draggable_region.cc', 'atom/common/draggable_region.h', 'atom/common/google_api_key.h', - 'atom/common/id_weak_map.cc', - 'atom/common/id_weak_map.h', 'atom/common/key_weak_map.h', 'atom/common/keyboard_util.cc', 'atom/common/keyboard_util.h', -- 2.7.4