From 4ac6034d925d0d282f61cff011e73589c4e802c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morel=20B=C3=A9renger?= Date: Mon, 14 Mar 2022 15:26:19 +0100 Subject: [PATCH 1/5] fix implicit cast warnings in a header --- src/common/Serialize.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/Serialize.h b/src/common/Serialize.h index 3bce5fd664..adcf07bc13 100644 --- a/src/common/Serialize.h +++ b/src/common/Serialize.h @@ -82,7 +82,7 @@ namespace Util { { if (size > std::numeric_limits::max()) Sys::Drop("IPC: Size out of range in message"); - Write(size); + Write(static_cast( size )); } template void Write(Arg&& value) { @@ -249,7 +249,7 @@ namespace Util { struct SerializeTraits { static void Write(Writer& stream, bool value) { - stream.Write(+value); + stream.Write(static_cast(value)); } static bool Read(Reader& stream) { From 4f53762690398305fb2606d14b06516a986eae4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morel=20B=C3=A9renger?= Date: Sun, 10 Nov 2024 01:40:06 +0100 Subject: [PATCH 2/5] InternalRecvMsg reserves before pushing --- src/common/IPC/Primitives.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/IPC/Primitives.cpp b/src/common/IPC/Primitives.cpp index 14bdd8c339..6ba3d58c94 100644 --- a/src/common/IPC/Primitives.cpp +++ b/src/common/IPC/Primitives.cpp @@ -361,6 +361,8 @@ bool InternalRecvMsg(Sys::OSHandle handle, Util::Reader& reader) if (hdr.flags & (NACL_MESSAGE_TRUNCATED | NACL_HANDLES_TRUNCATED)) Sys::Drop("IPC: Recieved truncated message"); + // NACL_ABI_IMC_DESC_MAX == 8 anyway, so let's avoid useless loops and reallocs + reader.GetHandles().reserve(reader.GetHandles().size() + NACL_ABI_IMC_DESC_MAX); for (size_t i = 0; i < NACL_ABI_IMC_DESC_MAX; i++) { if (h[i] != NACL_INVALID_HANDLE) { reader.GetHandles().emplace_back(); From 0e9875fb716ee8b9387f1fabdab9d63577ca22b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morel=20B=C3=A9renger?= Date: Sun, 10 Nov 2024 02:13:31 +0100 Subject: [PATCH 3/5] recvmsg: use std::fill instead of for-loop Seems faster --- src/common/IPC/Primitives.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/IPC/Primitives.cpp b/src/common/IPC/Primitives.cpp index 6ba3d58c94..2b8a7b7305 100644 --- a/src/common/IPC/Primitives.cpp +++ b/src/common/IPC/Primitives.cpp @@ -339,8 +339,7 @@ bool InternalRecvMsg(Sys::OSHandle handle, Util::Reader& reader) recvBuffer.reset(new char[NACL_ABI_IMC_BYTES_MAX]); } - for (size_t i = 0; i < NACL_ABI_IMC_DESC_MAX; i++) - h[i] = NACL_INVALID_HANDLE; + std::fill(std::begin(h), std::end(h), NACL_INVALID_HANDLE); #ifdef __native_client__ hdr.iov = iov; From 903fe954baf810fa6f42805e1511d597a92e2fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morel=20B=C3=A9renger?= Date: Mon, 13 Jan 2025 17:21:50 +0100 Subject: [PATCH 4/5] minor perf patch for IPC Reader --- src/common/Serialize.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/Serialize.h b/src/common/Serialize.h index adcf07bc13..23e3232f0c 100644 --- a/src/common/Serialize.h +++ b/src/common/Serialize.h @@ -132,10 +132,16 @@ namespace Util { public: Reader() : pos(0), handles_pos(0) {} + Reader(Reader const& other) = delete; + Reader& operator=(Reader const& other) = delete; Reader(Reader&& other) NOEXCEPT : data(std::move(other.data)), handles(std::move(other.handles)), pos(other.pos), handles_pos(other.handles_pos) {} Reader& operator=(Reader&& other) NOEXCEPT { + if (this == &other) + { + return *this; + } std::swap(data, other.data); std::swap(handles, other.handles); std::swap(pos, other.pos); @@ -145,8 +151,8 @@ namespace Util { ~Reader() { // Close any handles that weren't read - for (size_t i = handles_pos; i < handles.size(); i++) - handles[i].Close(); + for (auto it = handles.begin() + handles_pos; it != handles.end(); ++it) + it->Close(); } void ReadData(void* p, size_t len) From 2fc65bdf4b555cc05f450b0af1e426e2c62552cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morel=20B=C3=A9renger?= Date: Sun, 24 Nov 2024 20:36:42 +0100 Subject: [PATCH 5/5] use final keyword in some places --- src/engine/renderer/tr_local.h | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index a6cfc3d47e..f23352ab53 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -3441,23 +3441,23 @@ void GLimp_LogComment_( std::string comment ); virtual const RenderCommand *ExecuteSelf() const = 0; }; - struct SetColorCommand : public RenderCommand { + struct SetColorCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; Color::Color color; }; - struct SetColorGradingCommand : public RenderCommand { + struct SetColorGradingCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; image_t *image; int slot; }; - struct DrawBufferCommand : public RenderCommand { + struct DrawBufferCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int buffer; }; - struct SwapBuffersCommand : public RenderCommand { + struct SwapBuffersCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; }; struct StretchPicCommand : public RenderCommand { @@ -3469,25 +3469,25 @@ void GLimp_LogComment_( std::string comment ); float s1, t1; float s2, t2; }; - struct RotatedPicCommand : public StretchPicCommand { + struct RotatedPicCommand final : public StretchPicCommand { const RenderCommand *ExecuteSelf() const override; float angle; }; - struct GradientPicCommand : public StretchPicCommand { + struct GradientPicCommand final : public StretchPicCommand { const RenderCommand *ExecuteSelf() const override; Color::Color32Bit gradientColor; // color values 0-255 int gradientType; }; - struct Poly2dCommand : public RenderCommand { + struct Poly2dCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; polyVert_t *verts; int numverts; shader_t *shader; }; - struct Poly2dIndexedCommand : public RenderCommand { + struct Poly2dIndexedCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; polyVert_t *verts; @@ -3497,7 +3497,7 @@ void GLimp_LogComment_( std::string comment ); shader_t *shader; int translation[2]; }; - struct ScissorSetCommand : public RenderCommand { + struct ScissorSetCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int x; @@ -3505,22 +3505,22 @@ void GLimp_LogComment_( std::string comment ); int w; int h; }; - struct SetMatrixTransformCommand : public RenderCommand { + struct SetMatrixTransformCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; matrix_t matrix; }; - struct ResetMatrixTransformCommand : public RenderCommand { + struct ResetMatrixTransformCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; }; - struct DrawViewCommand : public RenderCommand { + struct DrawViewCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; bool depthPass; }; - struct SetupLightsCommand : public RenderCommand { + struct SetupLightsCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; @@ -3531,7 +3531,7 @@ void GLimp_LogComment_( std::string comment ); SSF_JPEG, SSF_PNG }; - struct ScreenshotCommand : public RenderCommand { + struct ScreenshotCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int x; @@ -3541,7 +3541,7 @@ void GLimp_LogComment_( std::string comment ); char fileName[MAX_OSPATH]; ssFormat_t format; }; - struct VideoFrameCommand : public RenderCommand { + struct VideoFrameCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; int width; @@ -3550,33 +3550,33 @@ void GLimp_LogComment_( std::string comment ); byte *encodeBuffer; bool motionJpeg; }; - struct RenderPostProcessCommand : public RenderCommand { + struct RenderPostProcessCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; }; - struct ClearBufferCommand : public RenderCommand { + struct ClearBufferCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; }; - struct PreparePortalCommand : public RenderCommand { + struct PreparePortalCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; drawSurf_t *surface; }; - struct FinalisePortalCommand : public RenderCommand { + struct FinalisePortalCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; trRefdef_t refdef; viewParms_t viewParms; drawSurf_t *surface; }; - struct EndOfListCommand : public RenderCommand { + struct EndOfListCommand final : public RenderCommand { const RenderCommand *ExecuteSelf() const override; };