Remove IDWeakMap
This commit is contained in:
parent
ea93553225
commit
c708ae8eb5
5 changed files with 12 additions and 67 deletions
|
@ -8,7 +8,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/browser/api/event_emitter.h"
|
#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/bind.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
|
@ -113,21 +113,26 @@ class TrackableObject : public TrackableObjectBase,
|
||||||
|
|
||||||
void AfterInit(v8::Isolate* isolate) override {
|
void AfterInit(v8::Isolate* isolate) override {
|
||||||
if (!weak_map_) {
|
if (!weak_map_) {
|
||||||
weak_map_.reset(new atom::IDWeakMap);
|
weak_map_.reset(new atom::KeyWeakMap<int32_t>);
|
||||||
}
|
}
|
||||||
weak_map_id_ = weak_map_->Add(isolate, Wrappable<T>::GetWrapper());
|
weak_map_id_ = ++next_id_;
|
||||||
|
weak_map_->Set(isolate, weak_map_id_, Wrappable<T>::GetWrapper());
|
||||||
if (wrapped_)
|
if (wrapped_)
|
||||||
AttachAsUserData(wrapped_);
|
AttachAsUserData(wrapped_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static scoped_ptr<atom::IDWeakMap> weak_map_;
|
static int32_t next_id_;
|
||||||
|
static scoped_ptr<atom::KeyWeakMap<int32_t>> weak_map_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(TrackableObject);
|
DISALLOW_COPY_AND_ASSIGN(TrackableObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
scoped_ptr<atom::IDWeakMap> TrackableObject<T>::weak_map_;
|
int32_t TrackableObject<T>::next_id_ = 0;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
scoped_ptr<atom::KeyWeakMap<int32_t>> TrackableObject<T>::weak_map_;
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
|
#ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
|
||||||
#define 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/object_template_builder.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class IDWeakMap : public mate::Wrappable<IDWeakMap> {
|
||||||
bool Has(int32_t id);
|
bool Has(int32_t id);
|
||||||
void Remove(int32_t id);
|
void Remove(int32_t id);
|
||||||
|
|
||||||
atom::IDWeakMap id_weak_map_;
|
atom::KeyWeakMap<int32_t> id_weak_map_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
|
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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<v8::Object> object) {
|
|
||||||
int32_t id = GetNextID();
|
|
||||||
Set(isolate, id, object);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t IDWeakMap::GetNextID() {
|
|
||||||
return ++next_id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
|
|
@ -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<int32_t> {
|
|
||||||
public:
|
|
||||||
IDWeakMap();
|
|
||||||
~IDWeakMap() override;
|
|
||||||
|
|
||||||
// Adds |object| to WeakMap and returns its allocated |id|.
|
|
||||||
int32_t Add(v8::Isolate* isolate, v8::Local<v8::Object> 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_
|
|
|
@ -338,8 +338,6 @@
|
||||||
'atom/common/draggable_region.cc',
|
'atom/common/draggable_region.cc',
|
||||||
'atom/common/draggable_region.h',
|
'atom/common/draggable_region.h',
|
||||||
'atom/common/google_api_key.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/key_weak_map.h',
|
||||||
'atom/common/keyboard_util.cc',
|
'atom/common/keyboard_util.cc',
|
||||||
'atom/common/keyboard_util.h',
|
'atom/common/keyboard_util.h',
|
||||||
|
|
Loading…
Add table
Reference in a new issue