Commit f76c11f3 authored by Kirill Smelkov's avatar Kirill Smelkov

context: Don't use dict in _ValueCtx

We always store just one key in there.
This will simplify transition to C.
parent 20761c55
...@@ -86,7 +86,7 @@ def pywith_cancel(parent): # -> ctx, cancel ...@@ -86,7 +86,7 @@ def pywith_cancel(parent): # -> ctx, cancel
# Returned context inherits from parent and in particular has all other # Returned context inherits from parent and in particular has all other
# (key, value) pairs provided by parent. # (key, value) pairs provided by parent.
def pywith_value(parent, object key, object value): # -> ctx def pywith_value(parent, object key, object value): # -> ctx
return _ValueCtx({key: value}, parent) return _ValueCtx(key, value, parent)
# with_deadline creates new context with deadline. # with_deadline creates new context with deadline.
# #
...@@ -289,19 +289,20 @@ cdef class _CancelCtx(_BaseCtx): ...@@ -289,19 +289,20 @@ cdef class _CancelCtx(_BaseCtx):
# _ValueCtx is context that carries key -> value. # _ValueCtx is context that carries key -> value.
cdef class _ValueCtx(_BaseCtx): cdef class _ValueCtx(_BaseCtx):
# {} (key, value) specific to this context. # (key, value) specific to this context.
# the rest of the keys are inherited from parents. # the rest of the keys are inherited from parents.
# does not change after setup. # does not change after setup.
cdef dict _kv cdef object _key
cdef object _value
def __init__(_ValueCtx ctx, dict kv, parent): def __init__(_ValueCtx ctx, object key, object value, parent):
super(_ValueCtx, ctx).__init__(None, parent) super(_ValueCtx, ctx).__init__(None, parent)
ctx._kv = kv ctx._key = key
ctx._value = value
def value(_ValueCtx ctx, object key): def value(_ValueCtx ctx, object key):
v = ctx._kv.get(key) if ctx._key == key:
if v is not None: return ctx._value
return v
return super(_ValueCtx, ctx).value(key) return super(_ValueCtx, ctx).value(key)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment