Просмотр исходного кода

LibGfx: Move ICC::Profile towards "Fallible Constructors" pattern

Not quite there yet due to check_required_tags() / check_tag_types(),
but getting closer :^)
Nico Weber 2 лет назад
Родитель
Сommit
9ba3c8e36d

+ 5 - 4
Userland/Libraries/LibGfx/ICC/Profile.cpp

@@ -1377,10 +1377,11 @@ ErrorOr<void> Profile::check_tag_types()
 
 ErrorOr<NonnullRefPtr<Profile>> Profile::try_load_from_externally_owned_memory(ReadonlyBytes bytes)
 {
-    auto profile = TRY(try_make_ref_counted<Profile>());
-    profile->m_header = TRY(read_header(bytes));
-    bytes = bytes.trim(profile->on_disk_size());
-    profile->m_tag_table = TRY(read_tag_table(bytes));
+    auto header = TRY(read_header(bytes));
+    bytes = bytes.trim(header.on_disk_size);
+    auto tag_table = TRY(read_tag_table(bytes));
+
+    auto profile = TRY(try_make_ref_counted<Profile>(header, move(tag_table)));
 
     TRY(profile->check_required_tags());
     TRY(profile->check_tag_types());

+ 6 - 0
Userland/Libraries/LibGfx/ICC/Profile.h

@@ -210,6 +210,12 @@ class Profile : public RefCounted<Profile> {
 public:
     static ErrorOr<NonnullRefPtr<Profile>> try_load_from_externally_owned_memory(ReadonlyBytes);
 
+    Profile(ProfileHeader const& header, OrderedHashMap<TagSignature, NonnullRefPtr<TagData>> tag_table)
+        : m_header(header)
+        , m_tag_table(move(tag_table))
+    {
+    }
+
     Optional<PreferredCMMType> preferred_cmm_type() const { return m_header.preferred_cmm_type; }
     Version version() const { return m_header.version; }
     DeviceClass device_class() const { return m_header.device_class; }