From 69aece92798f92f8e454131bfec4c5a80a9220c0 Mon Sep 17 00:00:00 2001 From: Hediadyoin1 Date: Mon, 13 Jun 2022 17:08:18 +0200 Subject: [PATCH] LibCore+LibGfx: Pass file-path as StringView --- Userland/Libraries/LibCore/MappedFile.cpp | 4 ++-- Userland/Libraries/LibCore/MappedFile.h | 4 ++-- Userland/Libraries/LibGfx/Bitmap.cpp | 4 ++-- Userland/Libraries/LibGfx/Bitmap.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibCore/MappedFile.cpp b/Userland/Libraries/LibCore/MappedFile.cpp index 627b7d1a395..b12573dae48 100644 --- a/Userland/Libraries/LibCore/MappedFile.cpp +++ b/Userland/Libraries/LibCore/MappedFile.cpp @@ -14,13 +14,13 @@ namespace Core { -ErrorOr> MappedFile::map(String const& path) +ErrorOr> MappedFile::map(StringView path) { auto fd = TRY(Core::System::open(path, O_RDONLY | O_CLOEXEC, 0)); return map_from_fd_and_close(fd, path); } -ErrorOr> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] String const& path) +ErrorOr> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] StringView path) { TRY(Core::System::fcntl(fd, F_SETFD, FD_CLOEXEC)); diff --git a/Userland/Libraries/LibCore/MappedFile.h b/Userland/Libraries/LibCore/MappedFile.h index d0fbbbd59c7..f2ca779b335 100644 --- a/Userland/Libraries/LibCore/MappedFile.h +++ b/Userland/Libraries/LibCore/MappedFile.h @@ -19,8 +19,8 @@ class MappedFile : public RefCounted { AK_MAKE_NONMOVABLE(MappedFile); public: - static ErrorOr> map(String const& path); - static ErrorOr> map_from_fd_and_close(int fd, String const& path); + static ErrorOr> map(StringView path); + static ErrorOr> map_from_fd_and_close(int fd, StringView path); ~MappedFile(); void* data() { return m_data; } diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 56619440b90..1e417d3ff8a 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -102,7 +102,7 @@ ErrorOr> Bitmap::try_create_wrapper(BitmapFormat format, I return adopt_ref(*new Bitmap(format, size, scale_factor, pitch, data)); } -ErrorOr> Bitmap::try_load_from_file(String const& path, int scale_factor) +ErrorOr> Bitmap::try_load_from_file(StringView path, int scale_factor) { if (scale_factor > 1 && path.starts_with("/res/")) { LexicalPath lexical_path { path }; @@ -129,7 +129,7 @@ ErrorOr> Bitmap::try_load_from_file(String const& path, in return try_load_from_fd_and_close(fd, path); } -ErrorOr> Bitmap::try_load_from_fd_and_close(int fd, String const& path) +ErrorOr> Bitmap::try_load_from_fd_and_close(int fd, StringView path) { auto file = TRY(Core::MappedFile::map_from_fd_and_close(fd, path)); if (auto decoder = ImageDecoder::try_create(file->bytes())) { diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index f556a25f523..a3ded476794 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -93,8 +93,8 @@ public: [[nodiscard]] static ErrorOr> try_create(BitmapFormat, IntSize const&, int intrinsic_scale = 1); [[nodiscard]] static ErrorOr> try_create_shareable(BitmapFormat, IntSize const&, int intrinsic_scale = 1); [[nodiscard]] static ErrorOr> try_create_wrapper(BitmapFormat, IntSize const&, int intrinsic_scale, size_t pitch, void*); - [[nodiscard]] static ErrorOr> try_load_from_file(String const& path, int scale_factor = 1); - [[nodiscard]] static ErrorOr> try_load_from_fd_and_close(int fd, String const& path); + [[nodiscard]] static ErrorOr> try_load_from_file(StringView path, int scale_factor = 1); + [[nodiscard]] static ErrorOr> try_load_from_fd_and_close(int fd, StringView path); [[nodiscard]] static ErrorOr> try_create_with_anonymous_buffer(BitmapFormat, Core::AnonymousBuffer, IntSize const&, int intrinsic_scale, Vector const& palette); static ErrorOr> try_create_from_serialized_byte_buffer(ByteBuffer&&);