From: Mike Bayer Date: Mon, 19 May 2014 21:43:54 +0000 (-0400) Subject: inlining X-Git-Tag: rel_1_0_0b1~437 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=665eced208b9e277f4b5cdb64f5ef0613938e11a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git inlining --- diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index 68b4f06115..7699e05786 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -288,12 +288,14 @@ class ClassManager(dict): def new_instance(self, state=None): instance = self.class_.__new__(self.class_) setattr(instance, self.STATE_ATTR, - state or self._state_constructor(instance, self)) + self._state_constructor(instance, self) + if not state else state) return instance def setup_instance(self, instance, state=None): setattr(instance, self.STATE_ATTR, - state or self._state_constructor(instance, self)) + self._state_constructor(instance, self) + if not state else state) def teardown_instance(self, instance): delattr(instance, self.STATE_ATTR) diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 8fcace9be1..7ea54d4cd0 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -318,10 +318,8 @@ def instance_processor(mapper, context, path, adapter, append_result = listeners.append_result or None populate_existing = context.populate_existing or mapper.always_refresh invoke_all_eagers = context.invoke_all_eagers - load_evt = mapper.class_manager.dispatch.load or None refresh_evt = mapper.class_manager.dispatch.refresh or None - instance_state = attributes.instance_state instance_dict = attributes.instance_dict @@ -335,8 +333,7 @@ def instance_processor(mapper, context, path, adapter, _populators(mapper, context, path, row, adapter, new_populators, existing_populators, - eager_populators - ) + eager_populators) if translate_row: for fn in translate_row: @@ -490,7 +487,7 @@ def instance_processor(mapper, context, path, adapter, if key not in state.unloaded: pop(state, dict_, row) - if isnew: + if isnew and refresh_evt: state.manager.dispatch.refresh(state, context, attrs) if result is not None: diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 768b73c21e..7ff243e3b3 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -56,6 +56,8 @@ class InstanceState(interfaces._InspectionAttr): expired = False deleted = False _load_pending = False + committed_state = util.immutabledict() + callables = util.immutabledict() is_instance = True @@ -63,8 +65,14 @@ class InstanceState(interfaces._InspectionAttr): self.class_ = obj.__class__ self.manager = manager self.obj = weakref.ref(obj, self._cleanup) - self.callables = {} - self.committed_state = {} + + @util.memoized_property + def callables(self): + return {} + + @util.memoized_property + def committed_state(self): + return {} @util.memoized_property def attrs(self): @@ -222,7 +230,8 @@ class InstanceState(interfaces._InspectionAttr): if instance_dict: instance_dict.discard(self) - self.callables = {} + if 'callables' in self.__dict__: + del self.callables self.session_id = self._strong_obj = None del self.obj @@ -555,17 +564,19 @@ class InstanceState(interfaces._InspectionAttr): @classmethod def _commit_all_states(self, iter, instance_dict=None): - """Mass version of commit_all().""" + """Mass / highly inlined version of commit_all().""" for state, dict_ in iter: - state.committed_state.clear() + state_dict = state.__dict__ + + if 'committed_state' in state_dict: + del state_dict['committed_state'] - # inline of: - # InstanceState._pending_mutations._reset(state) - state.__dict__.pop('_pending_mutations', None) + if '_pending_mutations' in state_dict: + del state_dict['_pending_mutations'] - callables = state.callables - if callables: + if 'callables' in state_dict: + callables = state.callables for key in list(callables): if key in dict_ and callables[key] is state: del callables[key]