From d50dcac5a2a11ac4cffc5231035a740dc953560e Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 10 Mar 2009 22:20:09 +0100 Subject: [PATCH] return value, not const reference, if return type is POD or ptr returning reference to POD types can be in fact slower than returning value. --- src/screen.h | 12 ++++++------ src/window.cpp | 4 ++-- src/window.h | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/screen.h b/src/screen.h index fc72f7a8..1cdf3324 100644 --- a/src/screen.h +++ b/src/screen.h @@ -33,7 +33,7 @@ class BasicScreen BasicScreen() : hasToBeResized(0) { } virtual ~BasicScreen() { } - virtual void *&Cmp() = 0; + virtual void *Cmp() = 0; virtual void Init() = 0; virtual void SwitchTo() = 0; @@ -69,9 +69,9 @@ template class Screen : public BasicScreen Screen() : w(0) { } virtual ~Screen() { } - virtual void *&Cmp(); + virtual void *Cmp(); - WindowType *&Main(); + WindowType *Main(); virtual void Refresh(); virtual void RefreshWindow(); @@ -82,12 +82,12 @@ template class Screen : public BasicScreen WindowType *w; }; -template void *&Screen::Cmp() +template void *Screen::Cmp() { - return *(void **)(void *)&w; + return w; } -template WindowType *&Screen::Main() +template WindowType *Screen::Main() { return w; } diff --git a/src/window.cpp b/src/window.cpp index af465c32..8c48c188 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -540,12 +540,12 @@ void Window::GotoXY(int x, int y) itsY = y; } -const int &Window::X() const + int Window::X() const { return itsX; } -const int &Window::Y() const +int Window::Y() const { return itsY; } diff --git a/src/window.h b/src/window.h index 73a7cb6f..990dbdc0 100644 --- a/src/window.h +++ b/src/window.h @@ -93,8 +93,8 @@ namespace NCurses std::string GetString(size_t length = -1, size_t width = 0, bool encrypted = 0) const { return GetString("", length, width, encrypted); } void GetXY(int &, int &); void GotoXY(int, int); - const int &X() const; - const int &Y() const; + int X() const; + int Y() const; void SetGetStringHelper(GetStringHelper helper) { itsGetStringHelper = helper; } void SetColor(Color, Color = clDefault);