From 13f5d1c03739e3cf8f6fede91835b32f60375e2b Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 15 Feb 2022 23:05:51 +0200 Subject: [PATCH] LibEDID: Store manufacturer id instead of allocating on each call This also let's us use a KString instead of a string when we're in the Kernel, which opens the path for OOM-failure propagation. --- Userland/Libraries/LibEDID/EDID.cpp | 17 ++++++++--------- Userland/Libraries/LibEDID/EDID.h | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibEDID/EDID.cpp b/Userland/Libraries/LibEDID/EDID.cpp index efd5cbb001..dcd99790b3 100644 --- a/Userland/Libraries/LibEDID/EDID.cpp +++ b/Userland/Libraries/LibEDID/EDID.cpp @@ -480,6 +480,12 @@ ErrorOr Parser::parse() } } + u16 packed_id = read_be(&raw_edid().vendor.manufacturer_id); + m_legacy_manufacturer_id[0] = (char)((u16)'A' + ((packed_id >> 10) & 0x1f) - 1); + m_legacy_manufacturer_id[1] = (char)((u16)'A' + ((packed_id >> 5) & 0x1f) - 1); + m_legacy_manufacturer_id[2] = (char)((u16)'A' + (packed_id & 0x1f) - 1); + m_legacy_manufacturer_id[3] = '\0'; + return {}; } @@ -555,16 +561,9 @@ StringView Parser::version() const #endif } -String Parser::legacy_manufacturer_id() const +StringView Parser::legacy_manufacturer_id() const { - u16 packed_id = read_be(&raw_edid().vendor.manufacturer_id); - char id[4] = { - (char)((u16)'A' + ((packed_id >> 10) & 0x1f) - 1), - (char)((u16)'A' + ((packed_id >> 5) & 0x1f) - 1), - (char)((u16)'A' + (packed_id & 0x1f) - 1), - '\0' - }; - return id; + return m_legacy_manufacturer_id; } #ifndef KERNEL diff --git a/Userland/Libraries/LibEDID/EDID.h b/Userland/Libraries/LibEDID/EDID.h index 9cf0ae02b2..b3f15696c4 100644 --- a/Userland/Libraries/LibEDID/EDID.h +++ b/Userland/Libraries/LibEDID/EDID.h @@ -88,7 +88,7 @@ public: static ErrorOr from_framebuffer_device(String const&, size_t); #endif - String legacy_manufacturer_id() const; + StringView legacy_manufacturer_id() const; #ifndef KERNEL String manufacturer_name() const; #endif @@ -453,6 +453,7 @@ private: #else String m_version; #endif + char m_legacy_manufacturer_id[4] {}; }; }