Bug 913640 - sprinkle MOZ_CONSTEXPR on gfx's typed units to reduce static constructors; r=kats
authorNathan Froyd <froydnj@mozilla.com>
Fri, 13 Sep 2013 12:34:20 -0400
changeset 147155 fb9df2cda8228d584750da40287bec61b9dd92af
parent 147154 1193eb976c83dc635942742da192427e7bf096bd
child 147156 52b319afe96567de56f105171546120ebf51a578
push id25287
push userkwierso@gmail.com
push dateSat, 14 Sep 2013 01:14:44 +0000
treeherdermozilla-central@53d5e43e23cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs913640
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 913640 - sprinkle MOZ_CONSTEXPR on gfx's typed units to reduce static constructors; r=kats
gfx/2d/BaseSize.h
gfx/2d/Point.h
gfx/2d/ScaleFactor.h
--- a/gfx/2d/BaseSize.h
+++ b/gfx/2d/BaseSize.h
@@ -1,31 +1,33 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_BASESIZE_H_
 #define MOZILLA_GFX_BASESIZE_H_
 
+#include "mozilla/Attributes.h"
+
 namespace mozilla {
 namespace gfx {
 
 /**
  * Do not use this class directly. Subclass it, pass that subclass as the
  * Sub parameter, and only use that subclass. This allows methods to safely
  * cast 'this' to 'Sub*'.
  */
 template <class T, class Sub>
 struct BaseSize {
   T width, height;
 
   // Constructors
-  BaseSize() : width(0), height(0) {}
-  BaseSize(T aWidth, T aHeight) : width(aWidth), height(aHeight) {}
+  MOZ_CONSTEXPR BaseSize() : width(0), height(0) {}
+  MOZ_CONSTEXPR BaseSize(T aWidth, T aHeight) : width(aWidth), height(aHeight) {}
 
   void SizeTo(T aWidth, T aHeight) { width = aWidth; height = aHeight; }
 
   bool IsEmpty() const {
     return width == 0 || height == 0;
   }
 
   // Note that '=' isn't defined so we'll get the
--- a/gfx/2d/Point.h
+++ b/gfx/2d/Point.h
@@ -70,18 +70,18 @@ IntPointTyped<units> RoundedToInt(const 
 }
 
 template<class units>
 struct IntSizeTyped :
   public BaseSize< int32_t, IntSizeTyped<units> >,
   public units {
   typedef BaseSize< int32_t, IntSizeTyped<units> > Super;
 
-  IntSizeTyped() : Super() {}
-  IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
+  MOZ_CONSTEXPR IntSizeTyped() : Super() {}
+  MOZ_CONSTEXPR IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {}
 
   // XXX When all of the code is ported, the following functions to convert to and from
   // unknown types should be removed.
 
   static IntSizeTyped<units> FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) {
     return IntSizeTyped<units>(aSize.width, aSize.height);
   }
 
--- a/gfx/2d/ScaleFactor.h
+++ b/gfx/2d/ScaleFactor.h
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_SCALEFACTOR_H_
 #define MOZILLA_GFX_SCALEFACTOR_H_
 
+#include "mozilla/Attributes.h"
+
 #include "gfxPoint.h"
 
 namespace mozilla {
 namespace gfx {
 
 /*
  * This class represents a scaling factor between two different pixel unit
  * systems. This is effectively a type-safe float, intended to be used in
@@ -21,19 +23,19 @@ namespace gfx {
  * were always expected to be the same, so this class uses only one scale
  * factor for both axes. The two constructors that take two-axis scaling
  * factors check to ensure that this assertion holds.
  */
 template<class src, class dst>
 struct ScaleFactor {
   float scale;
 
-  ScaleFactor() : scale(1.0) {}
-  ScaleFactor(const ScaleFactor<src, dst>& aCopy) : scale(aCopy.scale) {}
-  explicit ScaleFactor(float aScale) : scale(aScale) {}
+  MOZ_CONSTEXPR ScaleFactor() : scale(1.0) {}
+  MOZ_CONSTEXPR ScaleFactor(const ScaleFactor<src, dst>& aCopy) : scale(aCopy.scale) {}
+  explicit MOZ_CONSTEXPR ScaleFactor(float aScale) : scale(aScale) {}
 
   explicit ScaleFactor(float aX, float aY) : scale(aX) {
     MOZ_ASSERT(fabs(aX - aY) < 1e-6);
   }
 
   explicit ScaleFactor(gfxSize aScale) : scale(aScale.width) {
     MOZ_ASSERT(fabs(aScale.width - aScale.height) < 1e-6);
   }