Bug 893222 - Part 1: Add a new PutEscapedString implementation, which takes a raw jschar*. r=njn
☠☠ backed out by e9806317bc14 ☠ ☠
authorJustin Lebar <justin.lebar@gmail.com>
Fri, 02 Aug 2013 10:02:40 -0700
changeset 153446 3baebe7cc6554db020223ad205b4a2ca5ced2bd9
parent 153445 4bdf8611ec571174e377ab1143851f76e6d89a39
child 153447 d01358ff4b1559a1a7f51163442a6cee6a9800e2
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs893222
milestone25.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 893222 - Part 1: Add a new PutEscapedString implementation, which takes a raw jschar*. r=njn
js/src/jsstr.cpp
js/src/jsstr.h
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -4399,31 +4399,38 @@ js_OneUcs4ToUtf8Char(uint8_t *utf8Buffer
     }
     return utf8Length;
 }
 
 size_t
 js::PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, JSLinearString *str,
                          uint32_t quote)
 {
+    return PutEscapedStringImpl(buffer, bufferSize, fp, str->chars(),
+                                str->length(), quote);
+}
+
+size_t
+js::PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, const jschar *chars,
+                         size_t length, uint32_t quote)
+{
     enum {
         STOP, FIRST_QUOTE, LAST_QUOTE, CHARS, ESCAPE_START, ESCAPE_MORE
     } state;
 
     JS_ASSERT(quote == 0 || quote == '\'' || quote == '"');
     JS_ASSERT_IF(!buffer, bufferSize == 0);
     JS_ASSERT_IF(fp, !buffer);
 
     if (bufferSize == 0)
         buffer = NULL;
     else
         bufferSize--;
 
-    const jschar *chars = str->chars();
-    const jschar *charsEnd = chars + str->length();
+    const jschar *charsEnd = chars + length;
     size_t n = 0;
     state = FIRST_QUOTE;
     unsigned shift = 0;
     unsigned hex = 0;
     unsigned u = 0;
     char c = 0;  /* to quell GCC warnings */
 
     for (;;) {
--- a/js/src/jsstr.h
+++ b/js/src/jsstr.h
@@ -315,16 +315,20 @@ js_str_charCodeAt(JSContext *cx, unsigne
 extern int
 js_OneUcs4ToUtf8Char(uint8_t *utf8Buffer, uint32_t ucs4Char);
 
 namespace js {
 
 extern size_t
 PutEscapedStringImpl(char *buffer, size_t size, FILE *fp, JSLinearString *str, uint32_t quote);
 
+extern size_t
+PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, const jschar *chars,
+                     size_t length, uint32_t quote);
+
 /*
  * Write str into buffer escaping any non-printable or non-ASCII character
  * using \escapes for JS string literals.
  * Guarantees that a NUL is at the end of the buffer unless size is 0. Returns
  * the length of the written output, NOT including the NUL. Thus, a return
  * value of size or more means that the output was truncated. If buffer
  * is null, just returns the length of the output. If quote is not 0, it must
  * be a single or double quote character that will quote the output.
@@ -334,16 +338,26 @@ PutEscapedString(char *buffer, size_t si
 {
     size_t n = PutEscapedStringImpl(buffer, size, NULL, str, quote);
 
     /* PutEscapedStringImpl can only fail with a file. */
     JS_ASSERT(n != size_t(-1));
     return n;
 }
 
+inline size_t
+PutEscapedString(char *buffer, size_t bufferSize, const jschar *chars, size_t length, uint32_t quote)
+{
+    size_t n = PutEscapedStringImpl(buffer, bufferSize, NULL, chars, length, quote);
+
+    /* PutEscapedStringImpl can only fail with a file. */
+    JS_ASSERT(n != size_t(-1));
+    return n;
+}
+
 /*
  * Write str into file escaping any non-printable or non-ASCII character.
  * If quote is not 0, it must be a single or double quote character that
  * will quote the output.
 */
 inline bool
 FileEscapedString(FILE *fp, JSLinearString *str, uint32_t quote)
 {