1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

AK: Make HashMap::get(Key) return an Optional<Value>.

This allows HashMap::get() to be used for value types that cannot be default
constructed (e.g NonnullOwnPtr.)
This commit is contained in:
Andreas Kling 2019-07-24 10:25:43 +02:00
parent e2798d6208
commit 1d0b464618
10 changed files with 27 additions and 17 deletions

View file

@ -10,7 +10,7 @@ bool CArgsParserResult::is_present(const String& arg_name) const
String CArgsParserResult::get(const String& arg_name) const
{
return m_args.get(arg_name);
return m_args.get(arg_name).value_or({});
}
const Vector<String>& CArgsParserResult::get_single_values() const

View file

@ -92,7 +92,7 @@ void CHttpJob::on_socket_connected()
buffer.append(payload.pointer(), payload.size());
bool ok;
if (buffer.size() >= m_headers.get("Content-Length").to_int(ok) && ok) {
if (buffer.size() >= m_headers.get("Content-Length").value_or("0").to_int(ok) && ok) {
m_state = State::Finished;
break;
}

View file

@ -266,7 +266,7 @@ void GWindowServerConnection::postprocess_bundles(Vector<IncomingMessageBundle>&
}
switch (event.type) {
case WSAPI_ServerMessage::Type::Paint:
if (Size(event.paint.window_size) != latest_paint_size_for_window_id.get(event.window_id)) {
if (Size(event.paint.window_size) != latest_paint_size_for_window_id.get(event.window_id).value_or({})) {
++coalesced_paints;
break;
}
@ -295,7 +295,7 @@ void GWindowServerConnection::postprocess_bundles(Vector<IncomingMessageBundle>&
handle_window_entered_or_left_event(event, *window);
break;
case WSAPI_ServerMessage::Type::WindowResized:
if (Size(event.window.rect.size) != latest_size_for_window_id.get(event.window_id)) {
if (Size(event.window.rect.size) != latest_size_for_window_id.get(event.window_id).value_or({})) {
++coalesced_resizes;
break;
}

View file

@ -20,10 +20,10 @@ public:
void for_each_font(Function<void(const StringView&)>);
void for_each_fixed_width_font(Function<void(const StringView&)>);
Metadata get_metadata_by_name(const StringView& name) const
Optional<Metadata> get_metadata_by_name(const StringView& name) const
{
return m_name_to_metadata.get(name);
};
}
private:
GFontDatabase();