From: Ben Darnell Date: Mon, 17 Feb 2014 04:06:18 +0000 (-0500) Subject: Add a fast path to stack_context when there are no active contexts. X-Git-Tag: v4.0.0b1~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47c7f63f2464125e3c4392f2c516d75ed7048cd5;p=thirdparty%2Ftornado.git Add a fast path to stack_context when there are no active contexts. This case is increasingly common now that coroutines are decoupled from stack contexts. --- diff --git a/tornado/stack_context.py b/tornado/stack_context.py index b1e82b0e0..2e845ab27 100644 --- a/tornado/stack_context.py +++ b/tornado/stack_context.py @@ -266,6 +266,18 @@ def wrap(fn): # TODO: Any other better way to store contexts and update them in wrapped function? cap_contexts = [_state.contexts] + if not cap_contexts[0][0] and not cap_contexts[0][1]: + # Fast path when there are no active contexts. + def null_wrapper(*args, **kwargs): + try: + current_state = _state.contexts + _state.contexts = cap_contexts[0] + return fn(*args, **kwargs) + finally: + _state.contexts = current_state + null_wrapper._wrapped = True + return null_wrapper + def wrapped(*args, **kwargs): ret = None try: