Skip to content
Snippets Groups Projects
Commit a9aad6c2985d authored by Ilya Etingof's avatar Ilya Etingof
Browse files

Add minor performance optimising changes

parent 375c2ef9d9d3
Branches
No related tags found
No related merge requests found
...@@ -1471,6 +1471,9 @@ ...@@ -1471,6 +1471,9 @@
stStop) = [x for x in range(10)] stStop) = [x for x in range(10)]
EOO_SENTINEL = ints2octs((0, 0))
class SingleItemDecoder(object): class SingleItemDecoder(object):
defaultErrorState = stErrorCondition defaultErrorState = stErrorCondition
#defaultErrorState = stDumpRawValue #defaultErrorState = stDumpRawValue
...@@ -1487,7 +1490,6 @@ ...@@ -1487,7 +1490,6 @@
# Tag & TagSet objects caches # Tag & TagSet objects caches
self.__tagCache = {} self.__tagCache = {}
self.__tagSetCache = {} self.__tagSetCache = {}
self.__eooSentinel = ints2octs((0, 0))
def __call__(self, substrate, asn1Spec=None, def __call__(self, substrate, asn1Spec=None,
tagSet=None, length=None, state=stDecodeTag, tagSet=None, length=None, state=stDecodeTag,
...@@ -1508,7 +1510,7 @@ ...@@ -1508,7 +1510,7 @@
if isinstance(eoo_candidate, SubstrateUnderrunError): if isinstance(eoo_candidate, SubstrateUnderrunError):
yield eoo_candidate yield eoo_candidate
if eoo_candidate == self.__eooSentinel: if eoo_candidate == EOO_SENTINEL:
if LOG: if LOG:
LOG('end-of-octets sentinel found') LOG('end-of-octets sentinel found')
yield eoo.endOfOctets yield eoo.endOfOctets
......
...@@ -98,7 +98,10 @@ ...@@ -98,7 +98,10 @@
: :py:class:`~pyasn1.error.PyAsn1Error` : :py:class:`~pyasn1.error.PyAsn1Error`
If the supplied substrate cannot be converted to a seekable stream. If the supplied substrate cannot be converted to a seekable stream.
""" """
if isinstance(substrate, bytes): if isinstance(substrate, io.BytesIO):
return substrate
elif isinstance(substrate, bytes):
return io.BytesIO(substrate) return io.BytesIO(substrate)
elif isinstance(substrate, univ.OctetString): elif isinstance(substrate, univ.OctetString):
...@@ -225,7 +228,7 @@ ...@@ -225,7 +228,7 @@
if received is None: # non-blocking stream can do this if received is None: # non-blocking stream can do this
yield error.SubstrateUnderrunError(context=context) yield error.SubstrateUnderrunError(context=context)
elif size != 0 and not received: # end-of-stream elif not received and size != 0: # end-of-stream
raise error.EndOfStreamError(context=context) raise error.EndOfStreamError(context=context)
elif len(received) < size: elif len(received) < size:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment