From: Gaƫtan de Menten Date: Wed, 10 Oct 2007 16:15:29 +0000 (+0000) Subject: similar type optimization for the Interval type X-Git-Tag: rel_0_4_0~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ba1f5c45ef1d06e83c537bdce69a9d5f79d7d19b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git similar type optimization for the Interval type --- diff --git a/CHANGES b/CHANGES index e33c338549..2187433a6d 100644 --- a/CHANGES +++ b/CHANGES @@ -58,7 +58,8 @@ CHANGES - fixed Oracle non-ansi join syntax -- The PickleType is now slightly faster. +- PickleType and Interval types (on db not supporting it natively) are now + slightly faster. 0.4.0beta6 ---------- diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 02e36e0f34..1f18201d7f 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -535,14 +535,17 @@ class Interval(TypeDecorator): if self.__hasNativeImpl(dialect): return impl_processor else: - def process(value): - if value is None: - return None - tmpval = dt.datetime.utcfromtimestamp(0) + value - if impl_processor is not None: - return impl_processor(tmpval) - else: - return tmpval + zero_timestamp = dt.datetime.utcfromtimestamp(0) + if impl_processor is None: + def process(value): + if value is None: + return None + return zero_timestamp + value + else: + def process(value): + if value is None: + return None + return impl_processor(zero_timestamp + value) return process def result_processor(self, dialect): @@ -550,12 +553,17 @@ class Interval(TypeDecorator): if self.__hasNativeImpl(dialect): return impl_processor else: - def process(value): - if value is None: - return None - if impl_processor is not None: - value = impl_processor(value) - return value - dt.datetime.utcfromtimestamp(0) + zero_timestamp = dt.datetime.utcfromtimestamp(0) + if impl_processor is None: + def process(value): + if value is None: + return None + return value - zero_timestamp + else: + def process(value): + if value is None: + return None + return impl_processor(value) - zero_timestamp return process class FLOAT(Float):pass