فهرست منبع

LibPDF: Factorize duplicated code in `Filter::decode_ascii85()`

Lucas CHOLLET 1 سال پیش
والد
کامیت
59a6d4b7bc
1فایلهای تغییر یافته به همراه8 افزوده شده و 23 حذف شده
  1. 8 23
      Userland/Libraries/LibPDF/Filter.cpp

+ 8 - 23
Userland/Libraries/LibPDF/Filter.cpp

@@ -114,33 +114,18 @@ PDFErrorOr<ByteBuffer> Filter::decode_ascii85(ReadonlyBytes bytes)
 
 
         u32 number = 0;
         u32 number = 0;
 
 
-        if (byte_index + 5 >= bytes.size()) {
-            auto to_write = bytes.size() - byte_index;
-            for (int i = 0; i < 5; i++) {
-                auto byte = byte_index >= bytes.size() ? 'u' : bytes[byte_index++];
-                if (Reader::is_whitespace(byte)) {
-                    i--;
-                    continue;
-                }
-                number = number * 85 + byte - 33;
-            }
-
-            for (size_t i = 0; i < to_write - 1; i++)
-                buffer.append(reinterpret_cast<u8*>(&number)[3 - i]);
+        auto const to_write = byte_index + 5 >= bytes.size() ? bytes.size() - byte_index : 5;
 
 
-            break;
-        } else {
-            for (int i = 0; i < 5; i++) {
-                auto byte = bytes[byte_index++];
-                if (Reader::is_whitespace(byte)) {
-                    i--;
-                    continue;
-                }
-                number = number * 85 + byte - 33;
+        for (int i = 0; i < 5; i++) {
+            auto byte = byte_index >= bytes.size() ? 'u' : bytes[byte_index++];
+            if (Reader::is_whitespace(byte)) {
+                i--;
+                continue;
             }
             }
+            number = number * 85 + byte - 33;
         }
         }
 
 
-        for (int i = 0; i < 4; i++)
+        for (size_t i = 0; i < to_write - 1; i++)
             buffer.append(reinterpret_cast<u8*>(&number)[3 - i]);
             buffer.append(reinterpret_cast<u8*>(&number)[3 - i]);
     }
     }