Commit 45795dbe by Geoff Lang

Inline commonly used Error methods and add move operators.

The function call overhead of the constructors and assignement operators ended up being a hotspot even though the functions didn't do any significant work. BUG=angleproject:959 Change-Id: I96769879dabdbba7a222f98d87c5be0a829cb7dd Reviewed-on: https://chromium-review.googlesource.com/262335Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 11ffe1b8
...@@ -16,15 +16,9 @@ ...@@ -16,15 +16,9 @@
namespace gl namespace gl
{ {
Error::Error(GLenum errorCode)
: mCode(errorCode),
mMessage(NULL)
{
}
Error::Error(GLenum errorCode, const char *msg, ...) Error::Error(GLenum errorCode, const char *msg, ...)
: mCode(errorCode), : mCode(errorCode),
mMessage(NULL) mMessage(nullptr)
{ {
va_list vararg; va_list vararg;
va_start(vararg, msg); va_start(vararg, msg);
...@@ -33,39 +27,6 @@ Error::Error(GLenum errorCode, const char *msg, ...) ...@@ -33,39 +27,6 @@ Error::Error(GLenum errorCode, const char *msg, ...)
va_end(vararg); va_end(vararg);
} }
Error::Error(const Error &other)
: mCode(other.mCode),
mMessage(NULL)
{
if (other.mMessage != NULL)
{
createMessageString();
*mMessage = *(other.mMessage);
}
}
Error::~Error()
{
SafeDelete(mMessage);
}
Error &Error::operator=(const Error &other)
{
mCode = other.mCode;
if (other.mMessage != NULL)
{
createMessageString();
*mMessage = *(other.mMessage);
}
else
{
SafeDelete(mMessage);
}
return *this;
}
void Error::createMessageString() const void Error::createMessageString() const
{ {
if (mMessage == nullptr) if (mMessage == nullptr)
...@@ -85,13 +46,6 @@ const std::string &Error::getMessage() const ...@@ -85,13 +46,6 @@ const std::string &Error::getMessage() const
namespace egl namespace egl
{ {
Error::Error(EGLint errorCode)
: mCode(errorCode),
mID(0),
mMessage(nullptr)
{
}
Error::Error(EGLint errorCode, const char *msg, ...) Error::Error(EGLint errorCode, const char *msg, ...)
: mCode(errorCode), : mCode(errorCode),
mID(0), mID(0),
...@@ -115,42 +69,6 @@ Error::Error(EGLint errorCode, EGLint id, const char *msg, ...) ...@@ -115,42 +69,6 @@ Error::Error(EGLint errorCode, EGLint id, const char *msg, ...)
*mMessage = FormatString(msg, vararg); *mMessage = FormatString(msg, vararg);
va_end(vararg); va_end(vararg);
} }
Error::Error(const Error &other)
: mCode(other.mCode),
mID(other.mID),
mMessage(nullptr)
{
if (other.mMessage != nullptr)
{
createMessageString();
*mMessage = *(other.mMessage);
}
}
Error::~Error()
{
SafeDelete(mMessage);
}
Error &Error::operator=(const Error &other)
{
mCode = other.mCode;
mID = other.mID;
if (other.mMessage != nullptr)
{
createMessageString();
*mMessage = *(other.mMessage);
}
else
{
SafeDelete(mMessage);
}
return *this;
}
void Error::createMessageString() const void Error::createMessageString() const
{ {
if (mMessage == nullptr) if (mMessage == nullptr)
......
...@@ -17,17 +17,21 @@ ...@@ -17,17 +17,21 @@
namespace gl namespace gl
{ {
class Error class Error final
{ {
public: public:
explicit Error(GLenum errorCode); explicit inline Error(GLenum errorCode);
Error(GLenum errorCode, const char *msg, ...); Error(GLenum errorCode, const char *msg, ...);
Error(const Error &other); inline Error(const Error &other);
~Error(); inline Error(Error &&other);
Error &operator=(const Error &other);
GLenum getCode() const { return mCode; } inline ~Error();
bool isError() const { return (mCode != GL_NO_ERROR); }
inline Error &operator=(const Error &other);
inline Error &operator=(Error &&other);
inline GLenum getCode() const;
inline bool isError() const;
const std::string &getMessage() const; const std::string &getMessage() const;
...@@ -43,19 +47,23 @@ class Error ...@@ -43,19 +47,23 @@ class Error
namespace egl namespace egl
{ {
class Error class Error final
{ {
public: public:
explicit Error(EGLint errorCode); explicit inline Error(EGLint errorCode);
Error(EGLint errorCode, const char *msg, ...); Error(EGLint errorCode, const char *msg, ...);
Error(EGLint errorCode, EGLint id, const char *msg, ...); Error(EGLint errorCode, EGLint id, const char *msg, ...);
Error(const Error &other); inline Error(const Error &other);
~Error(); inline Error(Error &&other);
Error &operator=(const Error &other);
inline ~Error();
EGLint getCode() const { return mCode; } inline Error &operator=(const Error &other);
EGLint getID() const { return mID; } inline Error &operator=(Error &&other);
bool isError() const { return (mCode != EGL_SUCCESS); }
inline EGLint getCode() const;
inline EGLint getID() const;
inline bool isError() const;
const std::string &getMessage() const; const std::string &getMessage() const;
...@@ -69,4 +77,6 @@ class Error ...@@ -69,4 +77,6 @@ class Error
} }
#include "Error.inl"
#endif // LIBANGLE_ERROR_H_ #endif // LIBANGLE_ERROR_H_
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Error.inl: Inline definitions of egl::Error and gl::Error classes which encapsulate API errors
// and optional error messages.
#include "common/angleutils.h"
#include <cstdarg>
namespace gl
{
Error::Error(GLenum errorCode)
: mCode(errorCode),
mMessage(nullptr)
{
}
Error::Error(const Error &other)
: mCode(other.mCode),
mMessage(nullptr)
{
if (other.mMessage != nullptr)
{
createMessageString();
*mMessage = *(other.mMessage);
}
}
Error::Error(Error &&other)
: mCode(other.mCode),
mMessage(other.mMessage)
{
other.mMessage = nullptr;
}
Error::~Error()
{
SafeDelete(mMessage);
}
Error &Error::operator=(const Error &other)
{
mCode = other.mCode;
if (other.mMessage != nullptr)
{
createMessageString();
*mMessage = *(other.mMessage);
}
else
{
SafeDelete(mMessage);
}
return *this;
}
Error &Error::operator=(Error &&other)
{
mCode = other.mCode;
mMessage = other.mMessage;
other.mMessage = nullptr;
return *this;
}
GLenum Error::getCode() const
{
return mCode;
}
bool Error::isError() const
{
return (mCode != GL_NO_ERROR);
}
}
namespace egl
{
Error::Error(EGLint errorCode)
: mCode(errorCode),
mID(0),
mMessage(nullptr)
{
}
Error::Error(const Error &other)
: mCode(other.mCode),
mID(other.mID),
mMessage(nullptr)
{
if (other.mMessage != nullptr)
{
createMessageString();
*mMessage = *(other.mMessage);
}
}
Error::Error(Error &&other)
: mCode(other.mCode),
mID(other.mID),
mMessage(other.mMessage)
{
other.mMessage = nullptr;
}
Error::~Error()
{
SafeDelete(mMessage);
}
Error &Error::operator=(const Error &other)
{
mCode = other.mCode;
mID = other.mID;
if (other.mMessage != nullptr)
{
createMessageString();
*mMessage = *(other.mMessage);
}
else
{
SafeDelete(mMessage);
}
return *this;
}
Error &Error::operator=(Error &&other)
{
mCode = other.mCode;
mID = other.mID;
mMessage = other.mMessage;
other.mMessage = nullptr;
return *this;
}
EGLint Error::getCode() const
{
return mCode;
}
EGLint Error::getID() const
{
return mID;
}
bool Error::isError() const
{
return (mCode != EGL_SUCCESS);
}
}
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
'libANGLE/Display.h', 'libANGLE/Display.h',
'libANGLE/Error.cpp', 'libANGLE/Error.cpp',
'libANGLE/Error.h', 'libANGLE/Error.h',
'libANGLE/Error.inl',
'libANGLE/Fence.cpp', 'libANGLE/Fence.cpp',
'libANGLE/Fence.h', 'libANGLE/Fence.h',
'libANGLE/Float16ToFloat32.cpp', 'libANGLE/Float16ToFloat32.cpp',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment