mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: reduce AsyncWrap memory footprint
Fold two integral fields into one and use bitops to access/manipulate them. PR-URL: https://github.com/iojs/io.js/pull/667 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
1 parent
7e779b4593
commit
4bb3184d8d
3 files changed
+16
-11
No files matched your search
@@ -17,9 +17,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
|
||||
v8::Handle<v8::Object> object,
|
||||
ProviderType provider,
|
||||
AsyncWrap* parent)
|
||||
: BaseObject(env, object),
|
||||
has_async_queue_(false),
|
||||
provider_type_(provider) {
|
||||
: BaseObject(env, object), bits_(static_cast<uint32_t>(provider) << 1) {
|
||||
// Check user controlled flag to see if the init callback should run.
|
||||
if (!env->using_asyncwrap())
|
||||
return;
|
||||
@@ -49,7 +47,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
|
||||
if (try_catch.HasCaught())
|
||||
FatalError("node::AsyncWrap::AsyncWrap", "init hook threw");
|
||||
|
||||
has_async_queue_ = true;
|
||||
bits_ |= 1; // has_async_queue() is true now.
|
||||
|
||||
if (parent != nullptr) {
|
||||
env->async_hooks_post_function()->Call(parent_obj, 0, nullptr);
|
||||
@@ -59,8 +57,13 @@ inline AsyncWrap::AsyncWrap(Environment* env,
|
||||
}
|
||||
|
||||
|
||||
inline uint32_t AsyncWrap::provider_type() const {
|
||||
return provider_type_;
|
||||
inline bool AsyncWrap::has_async_queue() const {
|
||||
return static_cast<bool>(bits_ & 1);
|
||||
}
|
||||
|
||||
|
||||
inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
|
||||
return static_cast<ProviderType>(bits_ >> 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -104,7 +104,7 @@ Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
|
||||
}
|
||||
}
|
||||
|
||||
if (has_async_queue_) {
|
||||
if (has_async_queue()) {
|
||||
try_catch.SetVerbose(false);
|
||||
env()->async_hooks_pre_function()->Call(context, 0, nullptr);
|
||||
if (try_catch.HasCaught())
|
||||
@@ -118,7 +118,7 @@ Handle<Value> AsyncWrap::MakeCallback(const Handle<Function> cb,
|
||||
return Undefined(env()->isolate());
|
||||
}
|
||||
|
||||
if (has_async_queue_) {
|
||||
if (has_async_queue()) {
|
||||
try_catch.SetVerbose(false);
|
||||
env()->async_hooks_post_function()->Call(context, 0, nullptr);
|
||||
if (try_catch.HasCaught())
|
||||
|
||||
+5
-3
@@ -4,6 +4,8 @@
|
||||
#include "base-object.h"
|
||||
#include "v8.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace node {
|
||||
|
||||
#define NODE_ASYNC_PROVIDER_TYPES(V) \
|
||||
@@ -48,7 +50,7 @@ class AsyncWrap : public BaseObject {
|
||||
|
||||
inline virtual ~AsyncWrap() override = default;
|
||||
|
||||
inline uint32_t provider_type() const;
|
||||
inline ProviderType provider_type() const;
|
||||
|
||||
// Only call these within a valid HandleScope.
|
||||
v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
|
||||
@@ -63,12 +65,12 @@ class AsyncWrap : public BaseObject {
|
||||
|
||||
private:
|
||||
inline AsyncWrap();
|
||||
inline bool has_async_queue() const;
|
||||
|
||||
// When the async hooks init JS function is called from the constructor it is
|
||||
// expected the context object will receive a _asyncQueue object property
|
||||
// that will be used to call pre/post in MakeCallback.
|
||||
bool has_async_queue_;
|
||||
ProviderType provider_type_;
|
||||
uint32_t bits_;
|
||||
};
|
||||
|
||||
} // namespace node
|
||||
|
||||
Reference in new issue
Block a user