]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: hexdump should skip lines that are the same as previous
authorJason Dillaman <dillaman@redhat.com>
Thu, 28 Mar 2019 02:23:52 +0000 (22:23 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 11 Apr 2019 16:47:00 +0000 (12:47 -0400)
Previously, it would only skip similar lines if the data was all zeroed.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/common/buffer.cc

index 071c385ea9f5ffc420d0f682c8113b514edc52eb..0e9957a56f77307c50e33cf51a7e12925f57c84b 100644 (file)
@@ -2082,26 +2082,38 @@ void buffer::list::hexdump(std::ostream &out, bool trailing_newline) const
   out.fill('0');
 
   unsigned per = 16;
-  bool was_zeros = false, did_star = false;
+  char last_row_char = '\0';
+  bool was_same = false, did_star = false;
   for (unsigned o=0; o<length(); o += per) {
+    if (o == 0) {
+      last_row_char = (*this)[o];
+    }
+
     if (o + per < length()) {
-      bool row_is_zeros = true;
+      bool row_is_same = true;
       for (unsigned i=0; i<per && o+i<length(); i++) {
-       if ((*this)[o+i]) {
-         row_is_zeros = false;
+        char current_char = (*this)[o+i];
+        if (current_char != last_row_char) {
+          if (i == 0) {
+            last_row_char = current_char;
+            was_same = false;
+            did_star = false;
+          } else {
+           row_is_same = false;
+          }
        }
       }
-      if (row_is_zeros) {
-       if (was_zeros) {
+      if (row_is_same) {
+       if (was_same) {
          if (!did_star) {
            out << "\n*";
            did_star = true;
          }
          continue;
        }
-       was_zeros = true;
+       was_same = true;
       } else {
-       was_zeros = false;
+       was_same = false;
        did_star = false;
       }
     }