Make some arguments const/const references, where possible. NFC.

Found and suggested by clang-tidy.May help performance by reducing copies,
depending on frequency of call, etc.
pull/507/head
Ryan A. Pavlik 2019-11-23 08:07:31 -06:00 committed by whitequark
parent 65d0bdffdb
commit e386d405d6
15 changed files with 38 additions and 41 deletions

View File

@ -1068,8 +1068,9 @@ public:
} }
}; };
static void ImportDwgDxf(const Platform::Path &filename, static void
std::function<bool(const std::string &data, DRW_Interface *intf)> read) { ImportDwgDxf(const Platform::Path &filename,
const std::function<bool(const std::string &data, DRW_Interface *intf)> &read) {
std::string fileType = ToUpper(filename.Extension()); std::string fileType = ToUpper(filename.Extension());
std::string data; std::string data;

View File

@ -13,7 +13,7 @@ static System SYS;
static int IsInit = 0; static int IsInit = 0;
void SolveSpace::Platform::FatalError(std::string message) { void SolveSpace::Platform::FatalError(const std::string &message) {
fprintf(stderr, "%s", message.c_str()); fprintf(stderr, "%s", message.c_str());
abort(); abort();
} }

View File

@ -102,7 +102,7 @@ std::string AcceleratorDescription(const KeyboardEvent &accel);
#if defined(__GNUC__) #if defined(__GNUC__)
__attribute__((noreturn)) __attribute__((noreturn))
#endif #endif
void FatalError(std::string message); void FatalError(const std::string &message);
// A native settings store. // A native settings store.
class Settings { class Settings {

View File

@ -50,7 +50,7 @@ static std::string PrepareMnemonics(std::string label) {
return label; return label;
} }
static std::string PrepareTitle(std::string title) { static std::string PrepareTitle(const std::string &title) {
return title + " — SolveSpace"; return title + " — SolveSpace";
} }
@ -58,7 +58,7 @@ static std::string PrepareTitle(std::string title) {
// Fatal errors // Fatal errors
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FatalError(std::string message) { void FatalError(const std::string &message) {
fprintf(stderr, "%s", message.c_str()); fprintf(stderr, "%s", message.c_str());
abort(); abort();
} }

View File

@ -84,7 +84,7 @@ crash_info_t crashAnnotation __attribute__((section("__DATA,__crash_info"))) = {
CRASH_VERSION, NULL, NULL, NULL, NULL, NULL, NULL CRASH_VERSION, NULL, NULL, NULL, NULL, NULL, NULL
}; };
void FatalError(std::string message) { void FatalError(const std::string &message) {
crashAnnotation.message = message.c_str(); crashAnnotation.message = message.c_str();
abort(); abort();
} }

View File

@ -22,7 +22,7 @@ namespace Platform {
// Fatal errors // Fatal errors
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FatalError(std::string message) { void FatalError(const std::string &message) {
fprintf(stderr, "%s", message.c_str()); fprintf(stderr, "%s", message.c_str());
#if !defined(LIBRARY) && defined(HAVE_BACKTRACE) #if !defined(LIBRARY) && defined(HAVE_BACKTRACE)

View File

@ -152,13 +152,12 @@ static int Clamp(int x, int a, int b) {
bool handlingFatalError = false; bool handlingFatalError = false;
void FatalError(std::string message) { void FatalError(const std::string &message) {
// Indicate that we're handling a fatal error, to avoid re-entering application code // Indicate that we're handling a fatal error, to avoid re-entering application code
// and potentially crashing even harder. // and potentially crashing even harder.
handlingFatalError = true; handlingFatalError = true;
message += "\nGenerate debug report?"; switch(MessageBoxW(NULL, Platform::Widen(message + "\nGenerate debug report?").c_str(),
switch(MessageBoxW(NULL, Platform::Widen(message).c_str(),
L"Fatal error — SolveSpace", L"Fatal error — SolveSpace",
MB_ICONERROR|MB_TASKMODAL|MB_SETFOREGROUND|MB_TOPMOST| MB_ICONERROR|MB_TASKMODAL|MB_SETFOREGROUND|MB_TOPMOST|
MB_OKCANCEL|MB_DEFBUTTON2)) { MB_OKCANCEL|MB_DEFBUTTON2)) {

View File

@ -403,11 +403,10 @@ public:
Vertex *AddVertex(const Vector &pos); Vertex *AddVertex(const Vector &pos);
Edge *AddEdge(const Vector &p0, const Vector &p1, uint32_t kind, uintptr_t data = 0); Edge *AddEdge(const Vector &p0, const Vector &p1, uint32_t kind, uintptr_t data = 0);
void Generate( void Generate(std::function<void(Vertex *start, Vertex *next, Edge *edge)> const &startFunc,
std::function<void(Vertex *start, Vertex *next, Edge *edge)> startFunc, std::function<void(Vertex *next, Edge *edge)> const &nextFunc,
std::function<void(Vertex *next, Edge *edge)> nextFunc, std::function<void(Edge *)> const &aloneFunc,
std::function<void(Edge *)> aloneFunc, std::function<void()> const &endFunc = []() {});
std::function<void()> endFunc = [](){});
void MakeFromEdges(const SEdgeList &sel); void MakeFromEdges(const SEdgeList &sel);
void MakeFromOutlines(const SOutlineList &sol); void MakeFromOutlines(const SOutlineList &sol);

View File

@ -141,10 +141,9 @@ PolylineBuilder::Edge *PolylineBuilder::AddEdge(const Vector &p0, const Vector &
} }
void PolylineBuilder::Generate( void PolylineBuilder::Generate(
std::function<void(Vertex *start, Vertex *next, Edge *edge)> startFunc, std::function<void(Vertex *start, Vertex *next, Edge *edge)> const &startFunc,
std::function<void(Vertex *next, Edge *edge)> nextFunc, std::function<void(Vertex *next, Edge *edge)> const &nextFunc,
std::function<void(Edge *alone)> aloneFunc, std::function<void(Edge *alone)> const &aloneFunc, std::function<void()> const &endFunc) {
std::function<void()> endFunc) {
bool found; bool found;
bool loop = false; bool loop = false;
do { do {

View File

@ -162,7 +162,7 @@ void Shader::Clear() {
glDeleteProgram(program); glDeleteProgram(program);
} }
void Shader::SetUniformMatrix(const char *name, double *md) { void Shader::SetUniformMatrix(const char *name, const double *md) {
Enable(); Enable();
float mf[16]; float mf[16];
for(int i = 0; i < 16; i++) mf[i] = (float)md[i]; for(int i = 0; i < 16; i++) mf[i] = (float)md[i];
@ -621,11 +621,11 @@ void EdgeRenderer::Draw(const SEdgeList &edges) {
Remove(handle); Remove(handle);
} }
void EdgeRenderer::SetModelview(double *matrix) { void EdgeRenderer::SetModelview(const double *matrix) {
shader.SetUniformMatrix("modelview", matrix); shader.SetUniformMatrix("modelview", matrix);
} }
void EdgeRenderer::SetProjection(double *matrix) { void EdgeRenderer::SetProjection(const double *matrix) {
shader.SetUniformMatrix("projection", matrix); shader.SetUniformMatrix("projection", matrix);
} }
@ -833,11 +833,11 @@ void OutlineRenderer::Draw(const SOutlineList &outlines, Canvas::DrawOutlinesAs
Remove(handle); Remove(handle);
} }
void OutlineRenderer::SetModelview(double *matrix) { void OutlineRenderer::SetModelview(const double *matrix) {
shader.SetUniformMatrix("modelview", matrix); shader.SetUniformMatrix("modelview", matrix);
} }
void OutlineRenderer::SetProjection(double *matrix) { void OutlineRenderer::SetProjection(const double *matrix) {
shader.SetUniformMatrix("projection", matrix); shader.SetUniformMatrix("projection", matrix);
} }
@ -1037,14 +1037,14 @@ bool IndexedMeshRenderer::NeedsTexture() const {
selectedShader == &pointShader; selectedShader == &pointShader;
} }
void IndexedMeshRenderer::SetModelview(double *matrix) { void IndexedMeshRenderer::SetModelview(const double *matrix) {
colShader.SetUniformMatrix("modelview", matrix); colShader.SetUniformMatrix("modelview", matrix);
texShader.SetUniformMatrix("modelview", matrix); texShader.SetUniformMatrix("modelview", matrix);
texaShader.SetUniformMatrix("modelview", matrix); texaShader.SetUniformMatrix("modelview", matrix);
pointShader.SetUniformMatrix("modelview", matrix); pointShader.SetUniformMatrix("modelview", matrix);
} }
void IndexedMeshRenderer::SetProjection(double *matrix) { void IndexedMeshRenderer::SetProjection(const double *matrix) {
colShader.SetUniformMatrix("projection", matrix); colShader.SetUniformMatrix("projection", matrix);
texShader.SetUniformMatrix("projection", matrix); texShader.SetUniformMatrix("projection", matrix);
texaShader.SetUniformMatrix("projection", matrix); texaShader.SetUniformMatrix("projection", matrix);

View File

@ -74,7 +74,7 @@ public:
const std::vector<std::pair<GLuint, std::string>> &locations = {}); const std::vector<std::pair<GLuint, std::string>> &locations = {});
void Clear(); void Clear();
void SetUniformMatrix(const char *name, double *md); void SetUniformMatrix(const char *name, const double *md);
void SetUniformVector(const char *name, const Vector &v); void SetUniformVector(const char *name, const Vector &v);
void SetUniformVector(const char *name, const Vector4f &v); void SetUniformVector(const char *name, const Vector4f &v);
void SetUniformColor(const char *name, RgbaColor c); void SetUniformColor(const char *name, RgbaColor c);
@ -163,8 +163,8 @@ public:
void Draw(const Handle &handle); void Draw(const Handle &handle);
void Draw(const SEdgeList &edges); void Draw(const SEdgeList &edges);
void SetModelview(double *matrix); void SetModelview(const double *matrix);
void SetProjection(double *matrix); void SetProjection(const double *matrix);
void SetStroke(const Canvas::Stroke &stroke, double pixel); void SetStroke(const Canvas::Stroke &stroke, double pixel);
}; };
@ -203,8 +203,8 @@ public:
void Draw(const Handle &handle, Canvas::DrawOutlinesAs mode); void Draw(const Handle &handle, Canvas::DrawOutlinesAs mode);
void Draw(const SOutlineList &outlines, Canvas::DrawOutlinesAs mode); void Draw(const SOutlineList &outlines, Canvas::DrawOutlinesAs mode);
void SetModelview(double *matrix); void SetModelview(const double *matrix);
void SetProjection(double *matrix); void SetProjection(const double *matrix);
void SetStroke(const Canvas::Stroke &stroke, double pixel); void SetStroke(const Canvas::Stroke &stroke, double pixel);
}; };
@ -252,8 +252,8 @@ public:
void Draw(const Handle &handle); void Draw(const Handle &handle);
void Draw(const SIndexedMesh &mesh); void Draw(const SIndexedMesh &mesh);
void SetModelview(double *matrix); void SetModelview(const double *matrix);
void SetProjection(double *matrix); void SetProjection(const double *matrix);
bool NeedsTexture() const; bool NeedsTexture() const;

View File

@ -444,12 +444,11 @@ void ObjectPicker::DrawPixmap(std::shared_ptr<const Pixmap> pm,
DrawQuad(o, o.Plus(u), o.Plus(u).Plus(v), o.Plus(v), hcf); DrawQuad(o, o.Plus(u), o.Plus(u).Plus(v), o.Plus(v), hcf);
} }
bool ObjectPicker::Pick(std::function<void()> drawFn) { bool ObjectPicker::Pick(const std::function<void()> &drawFn) {
minDistance = VERY_POSITIVE; minDistance = VERY_POSITIVE;
maxZIndex = INT_MIN; maxZIndex = INT_MIN;
drawFn(); drawFn();
return minDistance < selRadius; return minDistance < selRadius;
} }
} }

View File

@ -261,7 +261,7 @@ public:
void DoQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d, void DoQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d,
int zIndex, int comparePosition = 0); int zIndex, int comparePosition = 0);
bool Pick(std::function<void()> drawFn); bool Pick(const std::function<void()> &drawFn);
}; };
// A canvas that renders onto a 2d surface, performing z-index sorting, occlusion testing, etc, // A canvas that renders onto a 2d surface, performing z-index sorting, occlusion testing, etc,

View File

@ -918,7 +918,7 @@ Vector VectorFont::GetExtents(double forCapHeight, const std::string &str) {
} }
void VectorFont::Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str, void VectorFont::Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str,
std::function<void(Vector, Vector)> traceEdge) { const std::function<void(Vector, Vector)> &traceEdge) {
ssassert(!IsEmpty(), "Expected a loaded font"); ssassert(!IsEmpty(), "Expected a loaded font");
double scale = (forCapHeight / capHeight); double scale = (forCapHeight / capHeight);
@ -945,7 +945,7 @@ void VectorFont::Trace(double forCapHeight, Vector o, Vector u, Vector v, const
} }
void VectorFont::Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str, void VectorFont::Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str,
std::function<void(Vector, Vector)> traceEdge, const Camera &camera) { const std::function<void(Vector, Vector)> &traceEdge, const Camera &camera) {
ssassert(!IsEmpty(), "Expected a loaded font"); ssassert(!IsEmpty(), "Expected a loaded font");
// Perform grid-fitting only when the text is parallel to the view plane. // Perform grid-fitting only when the text is parallel to the view plane.

View File

@ -103,9 +103,9 @@ public:
Vector GetExtents(double forCapHeight, const std::string &str); Vector GetExtents(double forCapHeight, const std::string &str);
void Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str, void Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str,
std::function<void(Vector, Vector)> traceEdge); const std::function<void(Vector, Vector)> &traceEdge);
void Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str, void Trace(double forCapHeight, Vector o, Vector u, Vector v, const std::string &str,
std::function<void(Vector, Vector)> traceEdge, const Camera &camera); const std::function<void(Vector, Vector)> &traceEdge, const Camera &camera);
}; };
#endif #endif