From 39baad9926b2d992b40ffb7b8f66459ddb21d439 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 17 Mar 2016 00:27:12 -0400 Subject: [PATCH 1/2] core/video_core: Don't cast away const in subscript operators Not to say these subscript operators aren't totally ugly as is. --- src/core/hw/gpu.h | 6 +++--- src/core/hw/lcd.h | 6 +++--- src/video_core/pica.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index 2e3a9f779..9e0701605 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h @@ -267,13 +267,13 @@ struct Regs { return sizeof(Regs) / sizeof(u32); } - u32& operator [] (int index) const { - u32* content = (u32*)this; + const u32& operator [] (int index) const { + const u32* content = reinterpret_cast(this); return content[index]; } u32& operator [] (int index) { - u32* content = (u32*)this; + u32* content = reinterpret_cast(this); return content[index]; } diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h index bcce6d8cf..d8ece4980 100644 --- a/src/core/hw/lcd.h +++ b/src/core/hw/lcd.h @@ -42,13 +42,13 @@ struct Regs { return sizeof(Regs) / sizeof(u32); } - u32& operator [] (int index) const { - u32* content = (u32*)this; + const u32& operator [] (int index) const { + const u32* content = reinterpret_cast(this); return content[index]; } u32& operator [] (int index) { - u32* content = (u32*)this; + u32* content = reinterpret_cast(this); return content[index]; } diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 7fb3aa481..d66124410 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -1225,13 +1225,13 @@ struct Regs { return sizeof(Regs) / sizeof(u32); } - u32& operator [] (int index) const { - u32* content = (u32*)this; + const u32& operator [] (int index) const { + const u32* content = reinterpret_cast(this); return content[index]; } u32& operator [] (int index) { - u32* content = (u32*)this; + u32* content = reinterpret_cast(this); return content[index]; } From c928b04eee9c17001c92643f69968945898694a7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 17 Mar 2016 00:29:47 -0400 Subject: [PATCH 2/2] core/video_core: Make NumIds functions constexpr --- src/core/hw/gpu.h | 2 +- src/core/hw/lcd.h | 2 +- src/video_core/pica.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index 9e0701605..a00adbf53 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h @@ -263,7 +263,7 @@ struct Regs { INSERT_PADDING_WORDS(0x9c3); - static inline size_t NumIds() { + static constexpr size_t NumIds() { return sizeof(Regs) / sizeof(u32); } diff --git a/src/core/hw/lcd.h b/src/core/hw/lcd.h index d8ece4980..3dd877fbf 100644 --- a/src/core/hw/lcd.h +++ b/src/core/hw/lcd.h @@ -38,7 +38,7 @@ struct Regs { u32 backlight_bottom; INSERT_PADDING_WORDS(0x16F); - static inline size_t NumIds() { + static constexpr size_t NumIds() { return sizeof(Regs) / sizeof(u32); } diff --git a/src/video_core/pica.h b/src/video_core/pica.h index d66124410..337cff8ce 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h @@ -1221,7 +1221,7 @@ struct Regs { // Used for debugging purposes, so performance is not an issue here static std::string GetCommandName(int index); - static inline size_t NumIds() { + static constexpr size_t NumIds() { return sizeof(Regs) / sizeof(u32); }