Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
codestyle fix
  • Loading branch information
individual-it authored Feb 27, 2017
commit a94cded2249f79f8654e95612564d4f33e56d5a7
9 changes: 5 additions & 4 deletions core/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1745,12 +1745,13 @@ OC.Util = {
*
*/
computerFileSize: function (string) {
if (typeof string != 'string') {
if (typeof string !== 'string') {
return null;
}

var s = string.toLowerCase();

var bytes = null;

var bytesArray = {
'b': 1,
'k': 1024,
Expand All @@ -1766,8 +1767,8 @@ OC.Util = {
};

var matches = s.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i);
Copy link
Contributor

@PVince81 PVince81 Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to pre-compile the regexp and store it in a hidden variable this._computerFileSizeRegexp or so.
I'm not sure if modern Javascript engines recompile the Regexp every time or whether it already caches it somewhere.

To be safe, store it somewhere so if this function is called in a loop it will run a bit faster.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it. please check it

if (matches != null) {
var bytes = parseFloat(s)
if (matches !== null) {
var bytes = parseFloat(s);
if (!isFinite(bytes)) {
return null;
}
Expand Down