Commit 6465f3ef authored by Vincent Pelletier's avatar Vincent Pelletier

Remove FIFO head & tail accessors.

Hotshot profiling shows FIFO.head() is called very often (~300k times for
embedded test suite). This change showed a ~30% speed increase for tested
case.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2553 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 30231671
...@@ -69,8 +69,8 @@ class FIFO(object): ...@@ -69,8 +69,8 @@ class FIFO(object):
""" """
def __init__(self): def __init__(self):
self._head = None self.head = None
self._tail = None self.tail = None
self._len = 0 self._len = 0
self.prev = None self.prev = None
self.data = None self.data = None
...@@ -88,23 +88,17 @@ class FIFO(object): ...@@ -88,23 +88,17 @@ class FIFO(object):
def append(self): def append(self):
element = Element() element = Element()
element.next = None element.next = None
element.prev = self._tail element.prev = self.tail
if self._tail is not None: if self.tail is not None:
self._tail.next = element self.tail.next = element
self._tail = element self.tail = element
if self._head is None: if self.head is None:
self._head = element self.head = element
self._len += 1 self._len += 1
return element return element
def head(self):
return self._head
def tail(self):
return self._tail
def shift(self): def shift(self):
element = self._head element = self.head
if element is None: if element is None:
return None return None
del self[element] del self[element]
...@@ -114,12 +108,12 @@ class FIFO(object): ...@@ -114,12 +108,12 @@ class FIFO(object):
def __delitem__(self, element): def __delitem__(self, element):
if element.next is None: if element.next is None:
self._tail = element.prev self.tail = element.prev
else: else:
element.next.prev = element.prev element.next.prev = element.prev
if element.prev is None: if element.prev is None:
self._head = element.next self.head = element.next
else: else:
element.prev.next = element.next element.prev.next = element.next
...@@ -297,7 +291,7 @@ class MQ(object): ...@@ -297,7 +291,7 @@ class MQ(object):
time = self._time time = self._time
for level in xrange(self._buffer_levels): for level in xrange(self._buffer_levels):
cache_buffer = cache_buffers[level] cache_buffer = cache_buffers[level]
head = cache_buffer.head() head = cache_buffer.head
if head is not None and head.data.expire_time < time: if head is not None and head.data.expire_time < time:
del cache_buffer[head] del cache_buffer[head]
data = head.data data = head.data
...@@ -316,7 +310,7 @@ class MQ(object): ...@@ -316,7 +310,7 @@ class MQ(object):
if self._size > max_size: if self._size > max_size:
for cache_buffer in cache_buffers: for cache_buffer in cache_buffers:
while self._size > max_size: while self._size > max_size:
element = cache_buffer.head() element = cache_buffer.head
if element is None: if element is None:
break break
self._evict(element.data.key) self._evict(element.data.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