From 06d86ebe84281ec53b83145b77e4a8a1a41a6fde Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 7 Dec 2011 13:31:55 -0800 Subject: [PATCH] Move node_http_parser.cc global vars into node_vars.h --- src/node_http_parser.cc | 98 ++++++++++++++++++++--------------------- src/node_vars.h | 84 ++++++++++++++++++++++++++--------- 2 files changed, 110 insertions(+), 72 deletions(-) diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 38251a1e7c..4cbde2253c 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -47,61 +47,57 @@ // allocations. +#include +// We do the following to minimize the detal between v0.6 branch. We want to +// use the variables as they were being used before. +#define on_headers_sym NODE_VAR(on_headers_sym) +#define on_headers_complete_sym NODE_VAR(on_headers_complete_sym) +#define on_body_sym NODE_VAR(on_body_sym) +#define on_message_complete_sym NODE_VAR(on_message_complete_sym) +#define delete_sym NODE_VAR(delete_sym) +#define get_sym NODE_VAR(get_sym) +#define head_sym NODE_VAR(head_sym) +#define post_sym NODE_VAR(post_sym) +#define put_sym NODE_VAR(put_sym) +#define connect_sym NODE_VAR(connect_sym) +#define options_sym NODE_VAR(options_sym) +#define trace_sym NODE_VAR(trace_sym) +#define patch_sym NODE_VAR(patch_sym) +#define copy_sym NODE_VAR(copy_sym) +#define lock_sym NODE_VAR(lock_sym) +#define mkcol_sym NODE_VAR(mkcol_sym) +#define move_sym NODE_VAR(move_sym) +#define propfind_sym NODE_VAR(propfind_sym) +#define proppatch_sym NODE_VAR(proppatch_sym) +#define unlock_sym NODE_VAR(unlock_sym) +#define report_sym NODE_VAR(report_sym) +#define mkactivity_sym NODE_VAR(mkactivity_sym) +#define checkout_sym NODE_VAR(checkout_sym) +#define merge_sym NODE_VAR(merge_sym) +#define msearch_sym NODE_VAR(msearch_sym) +#define notify_sym NODE_VAR(notify_sym) +#define subscribe_sym NODE_VAR(subscribe_sym) +#define unsubscribe_sym NODE_VAR(unsubscribe_sym) +#define unknown_method_sym NODE_VAR(unknown_method_sym) +#define method_sym NODE_VAR(method_sym) +#define status_code_sym NODE_VAR(status_code_sym) +#define http_version_sym NODE_VAR(http_version_sym) +#define version_major_sym NODE_VAR(version_major_sym) +#define version_minor_sym NODE_VAR(version_minor_sym) +#define should_keep_alive_sym NODE_VAR(should_keep_alive_sym) +#define upgrade_sym NODE_VAR(upgrade_sym) +#define headers_sym NODE_VAR(headers_sym) +#define url_sym NODE_VAR(url_sym) +#define settings NODE_VAR(settings) +#define current_buffer NODE_VAR(current_buffer) +#define current_buffer_data NODE_VAR(current_buffer_data) +#define current_buffer_len NODE_VAR(current_buffer_len) + + namespace node { using namespace v8; -static Persistent on_headers_sym; -static Persistent on_headers_complete_sym; -static Persistent on_body_sym; -static Persistent on_message_complete_sym; - -static Persistent delete_sym; -static Persistent get_sym; -static Persistent head_sym; -static Persistent post_sym; -static Persistent put_sym; -static Persistent connect_sym; -static Persistent options_sym; -static Persistent trace_sym; -static Persistent patch_sym; -static Persistent copy_sym; -static Persistent lock_sym; -static Persistent mkcol_sym; -static Persistent move_sym; -static Persistent propfind_sym; -static Persistent proppatch_sym; -static Persistent unlock_sym; -static Persistent report_sym; -static Persistent mkactivity_sym; -static Persistent checkout_sym; -static Persistent merge_sym; -static Persistent msearch_sym; -static Persistent notify_sym; -static Persistent subscribe_sym; -static Persistent unsubscribe_sym; -static Persistent unknown_method_sym; - -static Persistent method_sym; -static Persistent status_code_sym; -static Persistent http_version_sym; -static Persistent version_major_sym; -static Persistent version_minor_sym; -static Persistent should_keep_alive_sym; -static Persistent upgrade_sym; -static Persistent headers_sym; -static Persistent url_sym; - -static struct http_parser_settings settings; - - -// This is a hack to get the current_buffer to the callbacks with the least -// amount of overhead. Nothing else will run while http_parser_execute() -// runs, therefore this pointer can be set and used for the execution. -static Local* current_buffer; -static char* current_buffer_data; -static size_t current_buffer_len; - // gcc 3.x knows the always_inline attribute but fails at build time with a // "sorry, unimplemented: inlining failed" error when compiling at -O0 diff --git a/src/node_vars.h b/src/node_vars.h index 049be057ee..ce49dbaf3f 100644 --- a/src/node_vars.h +++ b/src/node_vars.h @@ -7,6 +7,7 @@ #include #include +#include #ifndef PATH_MAX # define PATH_MAX 4096 @@ -30,21 +31,6 @@ struct globals { v8::Persistent listeners_symbol; v8::Persistent uncaught_exception_symbol; v8::Persistent emit_symbol; - - // stream_wrap.cc - size_t slab_used; - uv_stream_t* handle_that_last_alloced; - v8::Persistent slab_sym; - v8::Persistent buffer_sym; - v8::Persistent write_queue_size_sym; - bool stream_wrap_initialized; - - // tcp_wrap.cc - v8::Persistent tcpConstructor; - v8::Persistent family_symbol; - v8::Persistent address_symbol; - v8::Persistent port_symbol; - bool print_eval; char *eval_string; int option_end_index; @@ -52,20 +38,16 @@ struct globals { bool debug_wait_connect; int debug_port; int max_stack_size; - uv_check_t check_tick_watcher; uv_prepare_t prepare_tick_watcher; uv_idle_t tick_spinner; bool need_tick_cb; v8::Persistent tick_callback_sym; - bool use_npn; bool use_sni; - // Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this // scoped at file-level rather than method-level to avoid excess stack usage. char getbuf[PATH_MAX + 1]; - // We need to notify V8 when we're idle so that it can run the garbage // collector. The interface to this is V8::IdleNotification(). It returns // true if the heap hasn't be fully compacted, and needs to be run again. @@ -77,13 +59,73 @@ struct globals { uv_idle_t gc_idle; uv_timer_t gc_timer; bool need_gc; - # define FAST_TICK 700. # define GC_WAIT_TIME 5000. # define RPM_SAMPLES 100 - int64_t tick_times[RPM_SAMPLES]; int tick_time_head; + + // stream_wrap.cc + size_t slab_used; + uv_stream_t* handle_that_last_alloced; + v8::Persistent slab_sym; + v8::Persistent buffer_sym; + v8::Persistent write_queue_size_sym; + bool stream_wrap_initialized; + + // tcp_wrap.cc + v8::Persistent tcpConstructor; + v8::Persistent family_symbol; + v8::Persistent address_symbol; + v8::Persistent port_symbol; + + // node_http_parser.cc + v8::Persistent on_headers_sym; + v8::Persistent on_headers_complete_sym; + v8::Persistent on_body_sym; + v8::Persistent on_message_complete_sym; + v8::Persistent delete_sym; + v8::Persistent get_sym; + v8::Persistent head_sym; + v8::Persistent post_sym; + v8::Persistent put_sym; + v8::Persistent connect_sym; + v8::Persistent options_sym; + v8::Persistent trace_sym; + v8::Persistent patch_sym; + v8::Persistent copy_sym; + v8::Persistent lock_sym; + v8::Persistent mkcol_sym; + v8::Persistent move_sym; + v8::Persistent propfind_sym; + v8::Persistent proppatch_sym; + v8::Persistent unlock_sym; + v8::Persistent report_sym; + v8::Persistent mkactivity_sym; + v8::Persistent checkout_sym; + v8::Persistent merge_sym; + v8::Persistent msearch_sym; + v8::Persistent notify_sym; + v8::Persistent subscribe_sym; + v8::Persistent unsubscribe_sym; + v8::Persistent unknown_method_sym; + v8::Persistent method_sym; + v8::Persistent status_code_sym; + v8::Persistent http_version_sym; + v8::Persistent version_major_sym; + v8::Persistent version_minor_sym; + v8::Persistent should_keep_alive_sym; + v8::Persistent upgrade_sym; + v8::Persistent headers_sym; + v8::Persistent url_sym; + struct http_parser_settings settings; + // This is a hack to get the current_buffer to the callbacks with the least + // amount of overhead. Nothing else will run while http_parser_execute() + // runs, therefore this pointer can be set and used for the execution. + v8::Local* current_buffer; + char* current_buffer_data; + size_t current_buffer_len; + }; struct globals* globals_get();