[tbb-commits] [tor-browser] 12/37: Bug 1771932 - Use more initializer lists in glsl.h. r=gw a=RyanVM

gitolite role git at cupani.torproject.org
Wed Jun 22 18:27:21 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-91.11.0esr-11.5-1
in repository tor-browser.

commit 7ab788b1ca3f84189c113d1695cd53c409f58641
Author: Lee Salzman <lsalzman at mozilla.com>
AuthorDate: Thu Jun 2 03:19:07 2022 +0000

    Bug 1771932 - Use more initializer lists in glsl.h. r=gw a=RyanVM
    
    Avoid assigning to fields in the constructor body when it is constexpr.
    
    Differential Revision: https://phabricator.services.mozilla.com/D148093
---
 gfx/wr/swgl/src/glsl.h | 51 ++++++++++++++------------------------------------
 1 file changed, 14 insertions(+), 37 deletions(-)

diff --git a/gfx/wr/swgl/src/glsl.h b/gfx/wr/swgl/src/glsl.h
index 3be1e49d1b2a1..01fcd4e2ca231 100644
--- a/gfx/wr/swgl/src/glsl.h
+++ b/gfx/wr/swgl/src/glsl.h
@@ -2255,14 +2255,9 @@ struct mat2_scalar {
   vec2_scalar data[2];
 
   mat2_scalar() = default;
-  IMPLICIT constexpr mat2_scalar(float a) {
-    data[0] = vec2_scalar(a);
-    data[1] = vec2_scalar(a);
-  }
-  constexpr mat2_scalar(vec2_scalar a, vec2_scalar b) {
-    data[0] = a;
-    data[1] = b;
-  }
+  IMPLICIT constexpr mat2_scalar(float a)
+      : data{vec2_scalar(a), vec2_scalar(a)} {}
+  constexpr mat2_scalar(vec2_scalar a, vec2_scalar b) : data{a, b} {}
   IMPLICIT mat2_scalar(const mat4_scalar& mat);
 
   vec2_scalar& operator[](int index) { return data[index]; }
@@ -2352,11 +2347,8 @@ struct mat3_scalar {
   vec3_scalar data[3];
 
   mat3_scalar() = default;
-  constexpr mat3_scalar(vec3_scalar a, vec3_scalar b, vec3_scalar c) {
-    data[0] = a;
-    data[1] = b;
-    data[2] = c;
-  }
+  constexpr mat3_scalar(vec3_scalar a, vec3_scalar b, vec3_scalar c)
+      : data{a, b, c} {}
   IMPLICIT mat3_scalar(const mat4_scalar& mat);
 
   vec3_scalar& operator[](int index) { return data[index]; }
@@ -2453,11 +2445,8 @@ struct mat3x4_scalar {
   vec4_scalar data[3];
 
   mat3x4_scalar() = default;
-  constexpr mat3x4_scalar(vec4_scalar a, vec4_scalar b, vec4_scalar c) {
-    data[0] = a;
-    data[1] = b;
-    data[2] = c;
-  }
+  constexpr mat3x4_scalar(vec4_scalar a, vec4_scalar b, vec4_scalar c)
+      : data{a, b, c} {}
 
   auto& operator[](int index) { return data[index]; }
   constexpr auto operator[](int index) const { return data[index]; }
@@ -2496,12 +2485,8 @@ struct mat4x3_scalar {
 
   mat4x3_scalar() = default;
   constexpr mat4x3_scalar(vec3_scalar a, vec3_scalar b, vec3_scalar c,
-                          vec3_scalar d) {
-    data[0] = a;
-    data[1] = b;
-    data[2] = c;
-    data[3] = d;
-  }
+                          vec3_scalar d)
+      : data{a, b, c, d} {}
 
   auto& operator[](int index) { return data[index]; }
   constexpr auto operator[](int index) const { return data[index]; }
@@ -2535,24 +2520,16 @@ struct mat4_scalar {
 
   mat4_scalar() = default;
   constexpr mat4_scalar(vec4_scalar a, vec4_scalar b, vec4_scalar c,
-                        vec4_scalar d) {
-    data[0] = a;
-    data[1] = b;
-    data[2] = c;
-    data[3] = d;
-  }
+                        vec4_scalar d)
+      : data{a, b, c, d} {}
 
   vec4_scalar& operator[](int index) { return data[index]; }
   const vec4_scalar& operator[](int index) const { return data[index]; }
 
   static mat4_scalar load_from_ptr(const float* f) {
-    mat4_scalar m;
-    // XXX: hopefully this is in the right order
-    m.data[0] = vec4_scalar{f[0], f[1], f[2], f[3]};
-    m.data[1] = vec4_scalar{f[4], f[5], f[6], f[7]};
-    m.data[2] = vec4_scalar{f[8], f[9], f[10], f[11]};
-    m.data[3] = vec4_scalar{f[12], f[13], f[14], f[15]};
-    return m;
+    return mat4_scalar(
+        vec4_scalar::load_from_ptr(&f[0]), vec4_scalar::load_from_ptr(&f[4]),
+        vec4_scalar::load_from_ptr(&f[8]), vec4_scalar::load_from_ptr(&f[12]));
   }
 
   friend vec4_scalar operator*(mat4_scalar m, vec4_scalar v) {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list