[Spice-commits] common/quic.c common/quic_family_tmpl.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu May 31 06:34:58 UTC 2018


 common/quic.c             |   20 ++++++++++++++------
 common/quic_family_tmpl.c |    4 +++-
 2 files changed, 17 insertions(+), 7 deletions(-)

New commits:
commit 68c0f93889fba893550541b699cb233f2dcbedfc
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun May 13 00:34:26 2018 +0100

    quic: Remove some too strict asserts in hot paths
    
    Some assert in the code are doing some paranoid test and in code
    paths quite hot.
    The encoding time is reduced by 30-50% while the decoding time
    is reduced by a 20-30%.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index a9a82ba..1ec6baa 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -400,8 +400,10 @@ static inline void encode(Encoder *encoder, unsigned int word, unsigned int len)
 {
     int delta;
 
-    spice_assert(len > 0 && len < 32);
-    spice_assert(!(word & ~bppmask[len]));
+    if (spice_extra_checks) {
+        spice_assert(len > 0 && len < 32);
+        spice_assert(!(word & ~bppmask[len]));
+    }
     if ((delta = ((int)encoder->io_available_bits - len)) >= 0) {
         encoder->io_available_bits = delta;
         encoder->io_word |= word << encoder->io_available_bits;
@@ -413,8 +415,10 @@ static inline void encode(Encoder *encoder, unsigned int word, unsigned int len)
     encoder->io_available_bits = 32 - delta;
     encoder->io_word = word << encoder->io_available_bits;
 
-    spice_assert(encoder->io_available_bits < 32);
-    spice_assert((encoder->io_word & bppmask[encoder->io_available_bits]) == 0);
+    if (spice_extra_checks) {
+        spice_assert(encoder->io_available_bits < 32);
+        spice_assert((encoder->io_word & bppmask[encoder->io_available_bits]) == 0);
+    }
 }
 
 static inline void encode_32(Encoder *encoder, unsigned int word)
@@ -437,7 +441,9 @@ static inline void read_io_word(Encoder *encoder)
     if (encoder->io_now == encoder->io_end) {
         more_io_words(encoder);
     }
-    spice_assert(encoder->io_now < encoder->io_end);
+    if (spice_extra_checks) {
+        spice_assert(encoder->io_now < encoder->io_end);
+    }
     encoder->io_next_word = GUINT32_FROM_LE(*(encoder->io_now++));
 }
 
@@ -445,7 +451,9 @@ static inline void decode_eatbits(Encoder *encoder, int len)
 {
     int delta;
 
-    spice_assert(len > 0 && len < 32);
+    if (spice_extra_checks) {
+        spice_assert(len > 0 && len < 32);
+    }
     encoder->io_word <<= len;
 
     if ((delta = ((int)encoder->io_available_bits - len)) >= 0) {
diff --git a/common/quic_family_tmpl.c b/common/quic_family_tmpl.c
index 9450f44..cda15bd 100644
--- a/common/quic_family_tmpl.c
+++ b/common/quic_family_tmpl.c
@@ -105,7 +105,9 @@ static void FNAME(update_model)(CommonState *state, s_bucket * const bucket,
 
 static s_bucket *FNAME(find_bucket)(Channel *channel, const unsigned int val)
 {
-    spice_assert(val < (0x1U << BPC));
+    if (spice_extra_checks) {
+        spice_assert(val < (0x1U << BPC));
+    }
 
     return channel->_buckets_ptrs[val];
 }


More information about the Spice-commits mailing list