You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ss...@apache.org on 2013/11/18 18:36:48 UTC

[3/3] git commit: Saved KB/MB/GB bytes as constants to save multiplication.

Saved KB/MB/GB bytes as constants to save multiplication.

Each time the 'dataSize' filter was called, the function did lots of
multiplication to get bytes per KB, MB, and GB to determine how to
print the string.

Moving the constants outside the function returned by the filter means
the multiplication is done only one time on app start up instead of in
each call.

* Added 1 digit to the right of the decimal point for GB. 6.5 GB is
  very different from 7 GB.

Review: http://reviews.apache.org/r/15579


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8fd1f555
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8fd1f555
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8fd1f555

Branch: refs/heads/master
Commit: 8fd1f55511d4cb6fb561f0e9e02bd95236c111e9
Parents: 0b736cf
Author: Ross Allen <ro...@gmail.com>
Authored: Thu Nov 14 11:03:38 2013 -0800
Committer: Ross Allen <ro...@gmail.com>
Committed: Mon Nov 18 09:35:56 2013 -0800

----------------------------------------------------------------------
 src/webui/master/static/js/app.js | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8fd1f555/src/webui/master/static/js/app.js
----------------------------------------------------------------------
diff --git a/src/webui/master/static/js/app.js b/src/webui/master/static/js/app.js
index 163c50b..728758d 100644
--- a/src/webui/master/static/js/app.js
+++ b/src/webui/master/static/js/app.js
@@ -83,17 +83,21 @@
       };
     })
     .filter('dataSize', function() {
+      var BYTES_PER_KB = Math.pow(2, 10);
+      var BYTES_PER_MB = Math.pow(2, 20);
+      var BYTES_PER_GB = Math.pow(2, 30);
+
       return function(bytes) {
-        if (bytes === null || bytes === undefined || isNaN(bytes)) {
+        if (bytes == null || isNaN(bytes)) {
           return '';
-        } else if (bytes < 1024) {
+        } else if (bytes < BYTES_PER_KB) {
           return bytes.toFixed() + ' B';
-        } else if (bytes < (1024 * 1024)) {
-          return (bytes / 1024).toFixed() + ' KB';
-        } else if (bytes < (1024 * 1024 * 1024)) {
-          return (bytes / (1024 * 1024)).toFixed() + ' MB';
+        } else if (bytes < BYTES_PER_MB) {
+          return (bytes / BYTES_PER_KB).toFixed() + ' KB';
+        } else if (bytes < BYTES_PER_GB) {
+          return (bytes / BYTES_PER_MB).toFixed() + ' MB';
         } else {
-          return (bytes / (1024 * 1024 * 1024)).toFixed() + ' GB';
+          return (bytes / BYTES_PER_GB).toFixed(1) + ' GB';
         }
       };
     })