浏览代码

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;
 
-        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]);
     }