summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-15 23:02:45 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-16 22:21:37 +0100
commit4a15ed616472e6badca8cfe8f30fb5e38a0391b6 (patch)
tree9a649b1f7a30086c96d09d60952be9dc8c5eb761 /Userland
parent5b572393a96e0ad1a916a422c47a257cd6da635b (diff)
downloadserenity-4a15ed616472e6badca8cfe8f30fb5e38a0391b6.zip
LibEDID: Store EDID version instead of allocating on each getter 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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibEDID/EDID.cpp14
-rw-r--r--Userland/Libraries/LibEDID/EDID.h15
-rw-r--r--Userland/Libraries/LibEDID/VIC.cpp1
3 files changed, 25 insertions, 5 deletions
diff --git a/Userland/Libraries/LibEDID/EDID.cpp b/Userland/Libraries/LibEDID/EDID.cpp
index 7e3b5f8d0d..efd5cbb001 100644
--- a/Userland/Libraries/LibEDID/EDID.cpp
+++ b/Userland/Libraries/LibEDID/EDID.cpp
@@ -462,6 +462,12 @@ ErrorOr<void> Parser::parse()
if (major_version != 1 || m_revision > 4)
return Error::from_string_literal("Unsupported Parser version"sv);
+#ifdef KERNEL
+ m_version = TRY(Kernel::KString::formatted("1.{}", (int)m_revision));
+#else
+ m_version = String::formatted("1.{}", (int)m_revision);
+#endif
+
u8 checksum = 0x0;
for (size_t i = 0; i < sizeof(Definitions::EDID); i++)
checksum += m_bytes[i];
@@ -540,9 +546,13 @@ ErrorOr<IterationDecision> Parser::for_each_extension_block(Function<IterationDe
return IterationDecision::Continue;
}
-String Parser::version() const
+StringView Parser::version() const
{
- return String::formatted("1.{}", (int)m_revision);
+#ifdef KERNEL
+ return m_version->view();
+#else
+ return m_version;
+#endif
}
String Parser::legacy_manufacturer_id() const
diff --git a/Userland/Libraries/LibEDID/EDID.h b/Userland/Libraries/LibEDID/EDID.h
index c42dd16cbb..9cf0ae02b2 100644
--- a/Userland/Libraries/LibEDID/EDID.h
+++ b/Userland/Libraries/LibEDID/EDID.h
@@ -6,17 +6,23 @@
#pragma once
+#include <AK/ByteBuffer.h>
#include <AK/ByteReader.h>
#include <AK/Endian.h>
#include <AK/Error.h>
#include <AK/FixedPoint.h>
#include <AK/Forward.h>
#include <AK/Span.h>
-#include <AK/String.h>
#include <AK/Vector.h>
#include <LibEDID/DMT.h>
#include <LibEDID/VIC.h>
+#ifdef KERNEL
+# include <Kernel/KString.h>
+#else
+# include <AK/String.h>
+#endif
+
namespace EDID {
namespace Definitions {
@@ -415,7 +421,7 @@ public:
bool operator==(Parser const& other) const;
- String version() const;
+ StringView version() const;
auto bytes() const { return m_bytes; }
@@ -442,6 +448,11 @@ private:
ByteBuffer m_bytes_buffer;
ReadonlyBytes m_bytes;
u8 m_revision { 0 };
+#ifdef KERNEL
+ OwnPtr<Kernel::KString> m_version;
+#else
+ String m_version;
+#endif
};
}
diff --git a/Userland/Libraries/LibEDID/VIC.cpp b/Userland/Libraries/LibEDID/VIC.cpp
index dd9e375898..460c664bde 100644
--- a/Userland/Libraries/LibEDID/VIC.cpp
+++ b/Userland/Libraries/LibEDID/VIC.cpp
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/String.h>
#include <LibEDID/VIC.h>
namespace EDID {