From 4a916cd3796cef0ef10374fcf9a602c96e226e6c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 9 Feb 2023 13:26:53 -0500 Subject: Everywhere: Remove needless copies of Error / ErrorOr instances Either take the underlying objects with release_* methods or move() the instances around. --- Kernel/Bus/PCI/Access.cpp | 4 ++-- Kernel/Net/IPv4Socket.cpp | 2 +- Kernel/PerformanceEventBuffer.cpp | 6 +++--- Kernel/PerformanceEventBuffer.h | 6 +++--- Kernel/PerformanceManager.h | 2 +- Kernel/Syscalls/read.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'Kernel') diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp index 4a78f43b99..507e968145 100644 --- a/Kernel/Bus/PCI/Access.cpp +++ b/Kernel/Bus/PCI/Access.cpp @@ -137,7 +137,7 @@ ErrorOr Access::add_host_controller_and_scan_for_devices(NonnullOwnPtrenumerate_attached_devices([&](EnumerableDeviceIdentifier const& device_identifier) -> IterationDecision { auto device_identifier_or_error = DeviceIdentifier::from_enumerable_identifier(device_identifier); if (device_identifier_or_error.is_error()) { - error_or_void = device_identifier_or_error.error(); + error_or_void = device_identifier_or_error.release_error(); return IterationDecision::Break; } m_device_identifiers.append(device_identifier_or_error.release_value()); @@ -167,7 +167,7 @@ UNMAP_AFTER_INIT void Access::rescan_hardware() (*it).value->enumerate_attached_devices([this, &error_or_void](EnumerableDeviceIdentifier device_identifier) -> IterationDecision { auto device_identifier_or_error = DeviceIdentifier::from_enumerable_identifier(device_identifier); if (device_identifier_or_error.is_error()) { - error_or_void = device_identifier_or_error.error(); + error_or_void = device_identifier_or_error.release_error(); return IterationDecision::Break; } m_device_identifiers.append(device_identifier_or_error.release_value()); diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 21de0cca03..c6dfeceb77 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -403,7 +403,7 @@ ErrorOr IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKer nreceived = receive_packet_buffered(description, offset_buffer, offset_buffer_length, flags, user_addr, user_addr_length, packet_timestamp, blocking); if (nreceived.is_error()) - total_nreceived = nreceived; + total_nreceived = move(nreceived); else total_nreceived.value() += nreceived.value(); } while ((flags & MSG_WAITALL) && !total_nreceived.is_error() && total_nreceived.value() < buffer_length); diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 71781b8b77..9c6c765fca 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -22,7 +22,7 @@ PerformanceEventBuffer::PerformanceEventBuffer(NonnullOwnPtr buffer) { } -NEVER_INLINE ErrorOr PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2, StringView arg3, Thread* current_thread, FlatPtr arg4, u64 arg5, ErrorOr arg6) +NEVER_INLINE ErrorOr PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2, StringView arg3, Thread* current_thread, FlatPtr arg4, u64 arg5, ErrorOr const& arg6) { FlatPtr base_pointer = (FlatPtr)__builtin_frame_address(0); return append_with_ip_and_bp(current_thread->pid(), current_thread->tid(), 0, base_pointer, type, 0, arg1, arg2, arg3, arg4, arg5, arg6); @@ -66,13 +66,13 @@ static Vector raw_backtrace(Fl } ErrorOr PerformanceEventBuffer::append_with_ip_and_bp(ProcessID pid, ThreadID tid, RegisterState const& regs, - int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4, u64 arg5, ErrorOr arg6) + int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4, u64 arg5, ErrorOr const& arg6) { return append_with_ip_and_bp(pid, tid, regs.ip(), regs.bp(), type, lost_samples, arg1, arg2, arg3, arg4, arg5, arg6); } ErrorOr PerformanceEventBuffer::append_with_ip_and_bp(ProcessID pid, ThreadID tid, - FlatPtr ip, FlatPtr bp, int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4, u64 arg5, ErrorOr arg6) + FlatPtr ip, FlatPtr bp, int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4, u64 arg5, ErrorOr const& arg6) { if (count() >= capacity()) return ENOBUFS; diff --git a/Kernel/PerformanceEventBuffer.h b/Kernel/PerformanceEventBuffer.h index bd246176b8..07cf54983d 100644 --- a/Kernel/PerformanceEventBuffer.h +++ b/Kernel/PerformanceEventBuffer.h @@ -110,11 +110,11 @@ class PerformanceEventBuffer { public: static OwnPtr try_create_with_size(size_t buffer_size); - ErrorOr append(int type, FlatPtr arg1, FlatPtr arg2, StringView arg3, Thread* current_thread = Thread::current(), FlatPtr arg4 = 0, u64 arg5 = 0, ErrorOr arg6 = 0); + ErrorOr append(int type, FlatPtr arg1, FlatPtr arg2, StringView arg3, Thread* current_thread = Thread::current(), FlatPtr arg4 = 0, u64 arg5 = 0, ErrorOr const& arg6 = 0); ErrorOr append_with_ip_and_bp(ProcessID pid, ThreadID tid, FlatPtr eip, FlatPtr ebp, - int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4 = 0, u64 arg5 = {}, ErrorOr arg6 = 0); + int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4 = 0, u64 arg5 = {}, ErrorOr const& arg6 = 0); ErrorOr append_with_ip_and_bp(ProcessID pid, ThreadID tid, RegisterState const& regs, - int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4 = 0, u64 arg5 = {}, ErrorOr arg6 = 0); + int type, u32 lost_samples, FlatPtr arg1, FlatPtr arg2, StringView arg3, FlatPtr arg4 = 0, u64 arg5 = {}, ErrorOr const& arg6 = 0); void clear() { diff --git a/Kernel/PerformanceManager.h b/Kernel/PerformanceManager.h index a236334339..36283e9da1 100644 --- a/Kernel/PerformanceManager.h +++ b/Kernel/PerformanceManager.h @@ -127,7 +127,7 @@ public: } } - static void add_read_event(Thread& thread, int fd, size_t size, OpenFileDescription const& file_description, u64 start_timestamp, ErrorOr result) + static void add_read_event(Thread& thread, int fd, size_t size, OpenFileDescription const& file_description, u64 start_timestamp, ErrorOr const& result) { if (thread.is_profiling_suppressed()) return; diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index f272b0c6de..3314b2bf37 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -74,7 +74,7 @@ ErrorOr Process::sys$readv(int fd, Userspace iov, ErrorOr Process::sys$read(int fd, Userspace buffer, size_t size) { auto const start_timestamp = TimeManagement::the().uptime_ms(); - auto const result = read_impl(fd, buffer, size); + auto result = read_impl(fd, buffer, size); if (Thread::current()->is_profiling_suppressed()) return result; -- cgit v1.2.3