From 4f638d3af25dd478e8a38d25c31d0a4b2e5b3d87 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Mon, 21 Aug 2023 16:45:46 +0200 Subject: [PATCH] Userland: Take StringView in MimeData::data() and has_{format,text,urls} --- Userland/Applications/Spreadsheet/SpreadsheetModel.cpp | 2 +- Userland/Applications/Spreadsheet/SpreadsheetView.cpp | 4 ++-- Userland/Libraries/LibCore/MimeData.h | 8 ++++---- Userland/Libraries/LibGUI/DragOperation.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp b/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp index 2caa1e31ec..21478f9392 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetModel.cpp @@ -153,7 +153,7 @@ RefPtr SheetModel::mime_data(const GUI::ModelSelection& selectio VERIFY(cursor); Position cursor_position { (size_t)cursor->column(), (size_t)cursor->row() }; - auto mime_data_buffer = mime_data->data("text/x-spreadsheet-data"); + auto mime_data_buffer = mime_data->data("text/x-spreadsheet-data"sv); auto new_data = DeprecatedString::formatted("{}\n{}", cursor_position.to_url(m_sheet).to_deprecated_string(), StringView(mime_data_buffer)); diff --git a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp index aa687c4dc4..4dcc4b7619 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetView.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetView.cpp @@ -420,8 +420,8 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet) ScopeGuard update_after_drop { [this] { update(); } }; - if (event.mime_data().has_format("text/x-spreadsheet-data")) { - auto const& data = event.mime_data().data("text/x-spreadsheet-data"); + if (event.mime_data().has_format("text/x-spreadsheet-data"sv)) { + auto const& data = event.mime_data().data("text/x-spreadsheet-data"sv); StringView urls { data.data(), data.size() }; Vector source_positions, target_positions; diff --git a/Userland/Libraries/LibCore/MimeData.h b/Userland/Libraries/LibCore/MimeData.h index 9be89de64f..d2f07a5617 100644 --- a/Userland/Libraries/LibCore/MimeData.h +++ b/Userland/Libraries/LibCore/MimeData.h @@ -20,19 +20,19 @@ class MimeData : public EventReceiver { public: virtual ~MimeData() = default; - ByteBuffer data(DeprecatedString const& mime_type) const { return m_data.get(mime_type).value_or({}); } + ByteBuffer data(StringView mime_type) const { return m_data.get(mime_type).value_or({}); } void set_data(DeprecatedString const& mime_type, ByteBuffer&& data) { m_data.set(mime_type, move(data)); } - bool has_format(DeprecatedString const& mime_type) const { return m_data.contains(mime_type); } + bool has_format(StringView mime_type) const { return m_data.contains(mime_type); } Vector formats() const; // Convenience helpers for "text/plain" - bool has_text() const { return has_format("text/plain"); } + bool has_text() const { return has_format("text/plain"sv); } DeprecatedString text() const; void set_text(DeprecatedString const&); // Convenience helpers for "text/uri-list" - bool has_urls() const { return has_format("text/uri-list"); } + bool has_urls() const { return has_format("text/uri-list"sv); } Vector urls() const; ErrorOr set_urls(Vector const&); diff --git a/Userland/Libraries/LibGUI/DragOperation.cpp b/Userland/Libraries/LibGUI/DragOperation.cpp index 04322dc6f7..5d1506f292 100644 --- a/Userland/Libraries/LibGUI/DragOperation.cpp +++ b/Userland/Libraries/LibGUI/DragOperation.cpp @@ -28,8 +28,8 @@ DragOperation::Outcome DragOperation::exec() VERIFY(m_mime_data); Gfx::ShareableBitmap drag_bitmap; - if (m_mime_data->has_format("image/x-raw-bitmap")) { - auto data = m_mime_data->data("image/x-raw-bitmap"); + if (m_mime_data->has_format("image/x-raw-bitmap"sv)) { + auto data = m_mime_data->data("image/x-raw-bitmap"sv); auto bitmap = Gfx::Bitmap::create_from_serialized_byte_buffer(move(data)).release_value_but_fixme_should_propagate_errors(); drag_bitmap = bitmap->to_shareable_bitmap(); }