Skip to content

Commit 400c1fc

Browse files
committed
Do not use String object for string functions
In date-format-xparb and date-format-tofte, we are unnecessarily creating String object from string. But we can just use String. This patch changes `new String(...)` to `String(...)` for stringifying.
1 parent 0976dde commit 400c1fc

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

SunSpider/date-format-tofte.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Date.prototype.formatDate = function (input,time) {
6969

7070
function d() {
7171
// Day of the month, 2 digits with leading zeros
72-
return new String(self.getDate()).length == 1?
72+
return String(self.getDate()).length == 1?
7373
"0"+self.getDate() : self.getDate();
7474
}
7575
function D() {
@@ -91,23 +91,23 @@ Date.prototype.formatDate = function (input,time) {
9191
function h() {
9292
// 12-hour format of an hour with leading zeros
9393
if (self.getHours() > 12) {
94-
var s = new String(self.getHours()-12);
94+
var s = String(self.getHours()-12);
9595
return s.length == 1?
9696
"0"+ (self.getHours()-12) : self.getHours()-12;
9797
} else {
98-
var s = new String(self.getHours());
98+
var s = String(self.getHours());
9999
return s.length == 1?
100100
"0"+self.getHours() : self.getHours();
101101
}
102102
}
103103
function H() {
104104
// 24-hour format of an hour with leading zeros
105-
return new String(self.getHours()).length == 1?
105+
return String(self.getHours()).length == 1?
106106
"0"+self.getHours() : self.getHours();
107107
}
108108
function i() {
109109
// Minutes with leading zeros
110-
return new String(self.getMinutes()).length == 1?
110+
return String(self.getMinutes()).length == 1?
111111
"0"+self.getMinutes() : self.getMinutes();
112112
}
113113
function j() {
@@ -169,7 +169,7 @@ Date.prototype.formatDate = function (input,time) {
169169
}
170170
function s() {
171171
// Seconds, with leading zeros
172-
return new String(self.getSeconds()).length == 1?
172+
return String(self.getSeconds()).length == 1?
173173
"0"+self.getSeconds() : self.getSeconds();
174174
}
175175
function t() {

SunSpider/date-format-xparb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ String.escape = function(string) {
349349
}
350350

351351
String.leftPad = function (val, size, ch) {
352-
var result = new String(val);
352+
var result = String(val);
353353
if (ch == null) {
354354
ch = " ";
355355
}

worker/bomb-subtests/date-format-tofte.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Date.prototype.formatDate = function (input,time) {
6969

7070
function d() {
7171
// Day of the month, 2 digits with leading zeros
72-
return new String(self.getDate()).length == 1?
72+
return String(self.getDate()).length == 1?
7373
"0"+self.getDate() : self.getDate();
7474
}
7575
function D() {
@@ -91,23 +91,23 @@ Date.prototype.formatDate = function (input,time) {
9191
function h() {
9292
// 12-hour format of an hour with leading zeros
9393
if (self.getHours() > 12) {
94-
var s = new String(self.getHours()-12);
94+
var s = String(self.getHours()-12);
9595
return s.length == 1?
9696
"0"+ (self.getHours()-12) : self.getHours()-12;
9797
} else {
98-
var s = new String(self.getHours());
98+
var s = String(self.getHours());
9999
return s.length == 1?
100100
"0"+self.getHours() : self.getHours();
101101
}
102102
}
103103
function H() {
104104
// 24-hour format of an hour with leading zeros
105-
return new String(self.getHours()).length == 1?
105+
return String(self.getHours()).length == 1?
106106
"0"+self.getHours() : self.getHours();
107107
}
108108
function i() {
109109
// Minutes with leading zeros
110-
return new String(self.getMinutes()).length == 1?
110+
return String(self.getMinutes()).length == 1?
111111
"0"+self.getMinutes() : self.getMinutes();
112112
}
113113
function j() {
@@ -169,7 +169,7 @@ Date.prototype.formatDate = function (input,time) {
169169
}
170170
function s() {
171171
// Seconds, with leading zeros
172-
return new String(self.getSeconds()).length == 1?
172+
return String(self.getSeconds()).length == 1?
173173
"0"+self.getSeconds() : self.getSeconds();
174174
}
175175
function t() {

worker/bomb-subtests/date-format-xparb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ String.escape = function(string) {
349349
}
350350

351351
String.leftPad = function (val, size, ch) {
352-
var result = new String(val);
352+
var result = String(val);
353353
if (ch == null) {
354354
ch = " ";
355355
}

0 commit comments

Comments
 (0)