Skip to content

[Book 1] Listing 4: use const references for parameters in utility functions #1250

@carvalhais

Description

@carvalhais

Regarding the following snippet from listing 4:

inline vec3 operator/(vec3 v, double t) {
    return (1/t) * v;
}

/* omitted code for brevity */

inline vec3 unit_vector(vec3 v) {
    return v / v.length();
}

They are the only utility functions that have parameters that are not constant references, and instead use copy-by value parameter passing. I believe change those parameters to const references would be more consistent with the other utility functions, and could even help a bit with performance (even though I'm no optimization expert), as in:

inline vec3 operator/(const vec3 &v, double t) {
    return (1/t) * v;
}

/* omitted code for brevity */

inline vec3 unit_vector(const vec3 &v) {
    return v / v.length();
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions