source: webkit/trunk/JavaScriptCore/runtime/DateConversion.cpp@ 52762

Last change on this file since 52762 was 52028, checked in by [email protected], 15 years ago

https://bugs.webkit.org/show_bug.cgi?id=32454
Refactor construction of simple strings to avoid string concatenation.

Reviewed by Oliver Hunt.

Building strings through concatenation has a memory and performance cost -
a memory cost since we must over-allocate the buffer to leave space to append
into, and performance in that the string may still require reallocation (and
thus copying during construction). Instead move the full construction to
within a single function call (makeString), so that the arguments' lengths
can be calculated and an appropriate sized buffer allocated before copying
any characters.

~No performance change (~2% progression on date tests).

  • bytecode/CodeBlock.cpp:

(JSC::escapeQuotes):
(JSC::valueToSourceString):
(JSC::constantName):
(JSC::idName):
(JSC::CodeBlock::registerName):
(JSC::regexpToSourceString):
(JSC::regexpName):

  • bytecompiler/NodesCodegen.cpp:

(JSC::substitute):

  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier):

  • runtime/DateConstructor.cpp:

(JSC::callDate):

  • runtime/DateConversion.cpp:

(JSC::formatDate):
(JSC::formatDateUTCVariant):
(JSC::formatTime):
(JSC::formatTimeUTC):

  • runtime/DateConversion.h:

(JSC::):

  • runtime/DatePrototype.cpp:

(JSC::dateProtoFuncToString):
(JSC::dateProtoFuncToUTCString):
(JSC::dateProtoFuncToDateString):
(JSC::dateProtoFuncToTimeString):
(JSC::dateProtoFuncToGMTString):

  • runtime/ErrorPrototype.cpp:

(JSC::errorProtoFuncToString):

  • runtime/ExceptionHelpers.cpp:

(JSC::createUndefinedVariableError):
(JSC::createErrorMessage):
(JSC::createInvalidParamError):

  • runtime/FunctionPrototype.cpp:

(JSC::insertSemicolonIfNeeded):
(JSC::functionProtoFuncToString):

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncToString):

  • runtime/RegExpConstructor.cpp:

(JSC::constructRegExp):

  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::match):

  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncCompile):
(JSC::regExpProtoFuncToString):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncBig):
(JSC::stringProtoFuncSmall):
(JSC::stringProtoFuncBlink):
(JSC::stringProtoFuncBold):
(JSC::stringProtoFuncFixed):
(JSC::stringProtoFuncItalics):
(JSC::stringProtoFuncStrike):
(JSC::stringProtoFuncSub):
(JSC::stringProtoFuncSup):
(JSC::stringProtoFuncFontcolor):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncAnchor):

  • runtime/UString.h:

(JSC::):
(JSC::makeString):

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 *
6 * The Original Code is Mozilla Communicator client code, released
7 * March 31, 1998.
8 *
9 * The Initial Developer of the Original Code is
10 * Netscape Communications Corporation.
11 * Portions created by the Initial Developer are Copyright (C) 1998
12 * the Initial Developer. All Rights Reserved.
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 *
28 * Alternatively, the contents of this file may be used under the terms
29 * of either the Mozilla Public License Version 1.1, found at
30 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
31 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
32 * (the "GPL"), in which case the provisions of the MPL or the GPL are
33 * applicable instead of those above. If you wish to allow use of your
34 * version of this file only under the terms of one of those two
35 * licenses (the MPL or the GPL) and not to allow others to use your
36 * version of this file under the LGPL, indicate your decision by
37 * deletingthe provisions above and replace them with the notice and
38 * other provisions required by the MPL or the GPL, as the case may be.
39 * If you do not delete the provisions above, a recipient may use your
40 * version of this file under any of the LGPL, the MPL or the GPL.
41 */
42
43#include "config.h"
44#include "DateConversion.h"
45
46#include "CallFrame.h"
47#include "UString.h"
48#include <wtf/DateMath.h>
49#include <wtf/StringExtras.h>
50
51using namespace WTF;
52
53namespace JSC {
54
55double parseDate(ExecState* exec, const UString &date)
56{
57 if (date == exec->globalData().cachedDateString)
58 return exec->globalData().cachedDateStringValue;
59 double value = parseDateFromNullTerminatedCharacters(exec, date.UTF8String().c_str());
60 exec->globalData().cachedDateString = date;
61 exec->globalData().cachedDateStringValue = value;
62 return value;
63}
64
65void formatDate(const GregorianDateTime &t, DateConversionBuffer& buffer)
66{
67 snprintf(buffer, DateConversionBufferSize, "%s %s %02d %04d",
68 weekdayName[(t.weekDay + 6) % 7],
69 monthName[t.month], t.monthDay, t.year + 1900);
70}
71
72void formatDateUTCVariant(const GregorianDateTime &t, DateConversionBuffer& buffer)
73{
74 snprintf(buffer, DateConversionBufferSize, "%s, %02d %s %04d",
75 weekdayName[(t.weekDay + 6) % 7],
76 t.monthDay, monthName[t.month], t.year + 1900);
77}
78
79void formatTime(const GregorianDateTime &t, DateConversionBuffer& buffer)
80{
81 int offset = abs(gmtoffset(t));
82 char timeZoneName[70];
83 struct tm gtm = t;
84 strftime(timeZoneName, sizeof(timeZoneName), "%Z", &gtm);
85
86 if (timeZoneName[0]) {
87 snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT%c%02d%02d (%s)",
88 t.hour, t.minute, t.second,
89 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, timeZoneName);
90 } else {
91 snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT%c%02d%02d",
92 t.hour, t.minute, t.second,
93 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60);
94 }
95}
96
97void formatTimeUTC(const GregorianDateTime &t, DateConversionBuffer& buffer)
98{
99 snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
100}
101
102} // namespace JSC
Note: See TracBrowser for help on using the repository browser.