Bug 733602 - Various StringBuffer cleanups, mostly removing unimplemented methods. r=luke
authorJeff Walden <jwalden@mit.edu>
Tue, 06 Mar 2012 15:28:48 -0800
changeset 88606 9d4c267630d43eaa0760a6cfe2c53f05b5a209d9
parent 88605 d5483dc182850c528d6a1bb9284097d899430666
child 88607 bd1bb076db6e306391d9f1df4ad10429c0c45dae
push id22208
push usermak77@bonardo.net
push dateFri, 09 Mar 2012 12:34:50 +0000
treeherdermozilla-central@ead9016b4102 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs733602
milestone13.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 733602 - Various StringBuffer cleanups, mostly removing unimplemented methods. r=luke
js/src/jsbool.cpp
js/src/jsbool.h
js/src/jsstr.cpp
js/src/vm/StringBuffer-inl.h
js/src/vm/StringBuffer.cpp
js/src/vm/StringBuffer.h
--- a/js/src/jsbool.cpp
+++ b/js/src/jsbool.cpp
@@ -181,23 +181,16 @@ js_InitBooleanClass(JSContext *cx, JSObj
 }
 
 JSString *
 js_BooleanToString(JSContext *cx, JSBool b)
 {
     return cx->runtime->atomState.booleanAtoms[b ? 1 : 0];
 }
 
-/* This function implements E-262-3 section 9.8, toString. */
-bool
-js::BooleanToStringBuffer(JSContext *cx, JSBool b, StringBuffer &sb)
-{
-    return b ? sb.append("true") : sb.append("false");
-}
-
 namespace js {
 
 bool
 BooleanGetPrimitiveValueSlow(JSContext *cx, JSObject &obj, Value *vp)
 {
     JS_ASSERT(ObjectClassIs(obj, ESClass_Boolean, cx));
     JS_ASSERT(obj.isProxy());
 
--- a/js/src/jsbool.h
+++ b/js/src/jsbool.h
@@ -49,19 +49,16 @@
 extern JSObject *
 js_InitBooleanClass(JSContext *cx, JSObject *obj);
 
 extern JSString *
 js_BooleanToString(JSContext *cx, JSBool b);
 
 namespace js {
 
-extern bool
-BooleanToStringBuffer(JSContext *cx, JSBool b, StringBuffer &sb);
-
 inline bool
 BooleanGetPrimitiveValue(JSContext *cx, JSObject &obj, Value *vp);
 
 } /* namespace js */
 
 extern JSBool
 js_ValueToBoolean(const js::Value &v);
 
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -3260,36 +3260,16 @@ js::ToStringSlow(JSContext *cx, const Va
     } else if (v.isNull()) {
         str = cx->runtime->atomState.nullAtom;
     } else {
         str = cx->runtime->atomState.typeAtoms[JSTYPE_VOID];
     }
     return str;
 }
 
-/* This function implements E-262-3 section 9.8, toString. */
-bool
-js::ValueToStringBufferSlow(JSContext *cx, const Value &arg, StringBuffer &sb)
-{
-    Value v = arg;
-    if (!ToPrimitive(cx, JSTYPE_STRING, &v))
-        return false;
-
-    if (v.isString())
-        return sb.append(v.toString());
-    if (v.isNumber())
-        return NumberValueToStringBuffer(cx, v, sb);
-    if (v.isBoolean())
-        return BooleanToStringBuffer(cx, v.toBoolean(), sb);
-    if (v.isNull())
-        return sb.append(cx->runtime->atomState.nullAtom);
-    JS_ASSERT(v.isUndefined());
-    return sb.append(cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
-}
-
 JS_FRIEND_API(JSString *)
 js_ValueToSource(JSContext *cx, const Value &v)
 {
     JS_CHECK_RECURSION(cx, return NULL);
 
     if (v.isUndefined())
         return cx->runtime->atomState.void0Atom;
     if (v.isString())
--- a/js/src/vm/StringBuffer-inl.h
+++ b/js/src/vm/StringBuffer-inl.h
@@ -62,23 +62,31 @@ StringBuffer::append(const jschar *begin
 inline bool
 StringBuffer::appendN(const jschar c, size_t n)
 {
     if (!checkLength(cb.length() + n))
         return false;
     return cb.appendN(c, n);
 }
 
+/* ES5 9.8 ToString, appending the result to the string buffer. */
 extern bool
 ValueToStringBufferSlow(JSContext *cx, const Value &v, StringBuffer &sb);
 
 inline bool
 ValueToStringBuffer(JSContext *cx, const Value &v, StringBuffer &sb)
 {
     if (v.isString())
         return sb.append(v.toString());
 
     return ValueToStringBufferSlow(cx, v, sb);
 }
 
+/* ES5 9.8 ToString for booleans, appending the result to the string buffer. */
+inline bool
+BooleanToStringBuffer(JSContext *cx, bool b, StringBuffer &sb)
+{
+    return b ? sb.append("true") : sb.append("false");
+}
+
 }  /* namespace js */
 
 #endif /* StringBuffer_inl_h__ */
--- a/js/src/vm/StringBuffer.cpp
+++ b/js/src/vm/StringBuffer.cpp
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  *
  * 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/. */
 
 #include "vm/StringBuffer.h"
 
+#include "jsobjinlines.h"
+
 #include "vm/String-inl.h"
 #include "vm/StringBuffer-inl.h"
 
 using namespace js;
 
 jschar *
 StringBuffer::extractWellSized()
 {
@@ -40,18 +42,17 @@ StringBuffer::extractWellSized()
 JSFixedString *
 StringBuffer::finishString()
 {
     JSContext *cx = context();
     if (cb.empty())
         return cx->runtime->atomState.emptyAtom;
 
     size_t length = cb.length();
-    if (!checkLength(length))
-        return NULL;
+    JS_ASSERT(checkLength(length));
 
     JS_STATIC_ASSERT(JSShortString::MAX_SHORT_LENGTH < CharBuffer::InlineLength);
     if (JSShortString::lengthFits(length))
         return NewShortString(cx, cb.begin(), length);
 
     if (!cb.append('\0'))
         return NULL;
 
@@ -73,8 +74,27 @@ StringBuffer::finishAtom()
     size_t length = cb.length();
     if (length == 0)
         return cx->runtime->atomState.emptyAtom;
 
     JSAtom *atom = js_AtomizeChars(cx, cb.begin(), length);
     cb.clear();
     return atom;
 }
+
+bool
+js::ValueToStringBufferSlow(JSContext *cx, const Value &arg, StringBuffer &sb)
+{
+    Value v = arg;
+    if (!ToPrimitive(cx, JSTYPE_STRING, &v))
+        return false;
+
+    if (v.isString())
+        return sb.append(v.toString());
+    if (v.isNumber())
+        return NumberValueToStringBuffer(cx, v, sb);
+    if (v.isBoolean())
+        return BooleanToStringBuffer(cx, v.toBoolean(), sb);
+    if (v.isNull())
+        return sb.append(cx->runtime->atomState.nullAtom);
+    JS_ASSERT(v.isUndefined());
+    return sb.append(cx->runtime->atomState.typeAtoms[JSTYPE_VOID]);
+}
--- a/js/src/vm/StringBuffer.h
+++ b/js/src/vm/StringBuffer.h
@@ -21,110 +21,96 @@ namespace js {
  * string length.
  *
  * Any operation which would exceed the maximum string length causes an
  * exception report on the context and results in a failed return value.
  *
  * Well-sized extractions (which waste no more than 1/4 of their char
  * buffer space) are guaranteed for strings built by this interface.
  * See |extractWellSized|.
- *
- * Note: over-allocation is not checked for when using the infallible
- * |replaceRawBuffer|, so the implementation of |finishString| also must check
- * for over-allocation.
  */
 class StringBuffer
 {
     /* cb's buffer is taken by the new string so use ContextAllocPolicy. */
     typedef Vector<jschar, 32, ContextAllocPolicy> CharBuffer;
 
     CharBuffer cb;
 
-    static inline bool checkLength(JSContext *cx, size_t length);
     inline bool checkLength(size_t length);
     JSContext *context() const { return cb.allocPolicy().context(); }
     jschar *extractWellSized();
 
     StringBuffer(const StringBuffer &other) MOZ_DELETE;
     void operator=(const StringBuffer &other) MOZ_DELETE;
 
   public:
-    explicit inline StringBuffer(JSContext *cx);
+    explicit StringBuffer(JSContext *cx) : cb(cx) { }
+
     inline bool reserve(size_t len);
     inline bool resize(size_t len);
     inline bool append(const jschar c);
     inline bool append(const jschar *chars, size_t len);
     inline bool append(const jschar *begin, const jschar *end);
     inline bool append(JSString *str);
     inline bool append(JSLinearString *str);
     inline bool appendN(const jschar c, size_t n);
     inline bool appendInflated(const char *cstr, size_t len);
 
+    template <size_t ArrayLength>
+    bool append(const char (&array)[ArrayLength]) {
+        return cb.append(array, array + ArrayLength - 1); /* No trailing '\0'. */
+    }
+
     /* Infallible variants usable when the corresponding space is reserved. */
     void infallibleAppend(const jschar c) {
         cb.infallibleAppend(c);
     }
     void infallibleAppend(const jschar *chars, size_t len) {
         cb.infallibleAppend(chars, len);
     }
     void infallibleAppend(const jschar *begin, const jschar *end) {
         cb.infallibleAppend(begin, end);
     }
     void infallibleAppendN(const jschar c, size_t n) {
         cb.infallibleAppendN(c, n);
     }
 
-    JSAtom *atomize(unsigned flags = 0);
-    static JSAtom *atomize(JSContext *cx, const CharBuffer &cb, unsigned flags = 0);
-    static JSAtom *atomize(JSContext *cx, const jschar *begin, size_t length, unsigned flags = 0);
-
-    void replaceRawBuffer(jschar *chars, size_t len) { cb.replaceRawBuffer(chars, len); }
     jschar *begin() { return cb.begin(); }
     jschar *end() { return cb.end(); }
     const jschar *begin() const { return cb.begin(); }
     const jschar *end() const { return cb.end(); }
     bool empty() const { return cb.empty(); }
     inline size_t length() const;
 
     /*
      * Creates a string from the characters in this buffer, then (regardless
      * whether string creation succeeded or failed) empties the buffer.
      */
     JSFixedString *finishString();
 
     /* Identical to finishString() except that an atom is created. */
     JSAtom *finishAtom();
-
-    template <size_t ArrayLength>
-    bool append(const char (&array)[ArrayLength]) {
-        return cb.append(array, array + ArrayLength - 1); /* No trailing '\0'. */
-    }
 };
 
-inline
-StringBuffer::StringBuffer(JSContext *cx)
-  : cb(cx)
-{}
+inline bool
+StringBuffer::append(JSLinearString *str)
+{
+    JS::Anchor<JSString *> anch(str);
+    return cb.append(str->chars(), str->length());
+}
 
 inline bool
 StringBuffer::append(JSString *str)
 {
     JSLinearString *linear = str->ensureLinear(context());
     if (!linear)
         return false;
     return append(linear);
 }
 
-inline bool
-StringBuffer::append(JSLinearString *str)
-{
-    JS::Anchor<JSString *> anch(str);
-    return cb.append(str->chars(), str->length());
-}
-
 inline size_t
 StringBuffer::length() const
 {
     JS_ASSERT(cb.length() <= JSString::MAX_LENGTH);
     return cb.length();
 }
 
 inline bool