Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 93bb280

Browse files
committed
Use deques in HPACK.
This is for the same reason as in d804f21.
1 parent d804f21 commit 93bb280

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

hyper/http20/hpack.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
88
Implements the version dated January 9, 2014.
99
"""
10+
import collections
11+
1012
from .huffman import HuffmanDecoder, HuffmanEncoder
1113
from hyper.http20.huffman_constants import (
1214
REQUEST_CODES, REQUEST_CODES_LENGTH, RESPONSE_CODES, RESPONSE_CODES_LENGTH
@@ -148,7 +150,7 @@ class Encoder(object):
148150
]
149151

150152
def __init__(self):
151-
self.header_table = []
153+
self.header_table = collections.deque()
152154
self.reference_set = set()
153155
self._header_table_size = 4096 # This value set by the standard.
154156
self.huffman_coder = HuffmanEncoder(
@@ -342,7 +344,7 @@ def _add_to_header_table(self, name, value):
342344
Adds a header to the header table, evicting old ones if necessary.
343345
"""
344346
# Be optimistic: add the header straight away.
345-
self.header_table.insert(0, (name, value))
347+
self.header_table.appendleft((name, value))
346348

347349
# Now, work out how big the header table is.
348350
actual_size = header_table_size(self.header_table)
@@ -478,7 +480,7 @@ class Decoder(object):
478480
]
479481

480482
def __init__(self):
481-
self.header_table = []
483+
self.header_table = collections.deque()
482484
self.reference_set = set()
483485
self._header_table_size = 4096 # This value set by the standard.
484486
self.huffman_coder = HuffmanDecoder(
@@ -553,7 +555,7 @@ def _add_to_header_table(self, name, value):
553555
Adds a header to the header table, evicting old ones if necessary.
554556
"""
555557
# Be optimistic: add the header straight away.
556-
self.header_table.insert(0, (name, value))
558+
self.header_table.appendleft((name, value))
557559

558560
# Now, work out how big the header table is.
559561
actual_size = header_table_size(self.header_table)

0 commit comments

Comments
 (0)