[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Cache string representation of messages



commit d69567629fb59df07237b7e0412ea6d310b0bcb1
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Oct 29 22:56:19 2017 -0700

    Cache string representation of messages
    
    Controller messages frequently reference their string representation, and it's
    silly to reconstruct it each time.
---
 stem/response/__init__.py | 6 +++++-
 stem/util/log.py          | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index e0de0f5c..362b8931 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -169,6 +169,7 @@ class ControlMessage(object):
 
     self._parsed_content = parsed_content
     self._raw_content = raw_content
+    self._str = None
 
   def is_ok(self):
     """
@@ -245,7 +246,10 @@ class ControlMessage(object):
     formatting.
     """
 
-    return '\n'.join(list(self))
+    if self._str is None:
+      self._str = '\n'.join(list(self))
+
+    return self._str
 
   def __iter__(self):
     """
diff --git a/stem/util/log.py b/stem/util/log.py
index 88b533e6..d2a6e5be 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -219,8 +219,8 @@ class LogBuffer(logging.Handler):
   Basic log handler that listens for stem events and stores them so they can be
   read later. Log entries are cleared as they are read.
 
-    .. versionchanged:: 1.4.0
-       Added the yield_records argument.
+  .. versionchanged:: 1.4.0
+     Added the yield_records argument.
   """
 
   def __init__(self, runlevel, yield_records = False):

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits