فهرست منبع

LibPDF: Use make_object<>() to make objects

No behavior change.
Nico Weber 1 سال پیش
والد
کامیت
13641693cb
2فایلهای تغییر یافته به همراه4 افزوده شده و 4 حذف شده
  1. 3 3
      Tests/LibPDF/TestPDF.cpp
  2. 1 1
      Userland/Libraries/LibPDF/Document.cpp

+ 3 - 3
Tests/LibPDF/TestPDF.cpp

@@ -113,7 +113,7 @@ static PDF::Value make_array(Vector<float> floats)
     Vector<PDF::Value> values;
     for (auto f : floats)
         values.append(PDF::Value { f });
-    return PDF::Value { adopt_ref(*new PDF::ArrayObject(move(values))) };
+    return PDF::Value { make_object<PDF::ArrayObject>(move(values)) };
 }
 
 static PDF::PDFErrorOr<NonnullRefPtr<PDF::Function>> make_function(int type, ReadonlyBytes data, Vector<float> domain, Vector<float> range, Function<void(HashMap<DeprecatedFlyString, PDF::Value>&)> extra_keys = nullptr)
@@ -124,8 +124,8 @@ static PDF::PDFErrorOr<NonnullRefPtr<PDF::Function>> make_function(int type, Rea
     map.set(PDF::CommonNames::Range, make_array(move(range)));
     if (extra_keys)
         extra_keys(map);
-    auto dict = adopt_ref(*new PDF::DictObject(move(map)));
-    auto stream = adopt_ref(*new PDF::StreamObject(dict, MUST(ByteBuffer::copy(data))));
+    auto dict = make_object<PDF::DictObject>(move(map));
+    auto stream = make_object<PDF::StreamObject>(dict, MUST(ByteBuffer::copy(data)));
 
     // document isn't used for anything, but UBSan complains about a (harmless) method call on a null object without it.
     auto file = MUST(Core::MappedFile::map("linearized.pdf"sv));

+ 1 - 1
Userland/Libraries/LibPDF/Document.cpp

@@ -235,7 +235,7 @@ PDFErrorOr<Page> Document::get_page(u32 index)
     if (maybe_resources_object.has_value())
         resources = maybe_resources_object.value()->cast<DictObject>();
     else
-        resources = adopt_ref(*new DictObject({}));
+        resources = make_object<DictObject>(HashMap<DeprecatedFlyString, Value> {});
 
     RefPtr<Object> contents;
     if (raw_page_object->contains(CommonNames::Contents))