1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
#ifndef jsstrinlines_h___
8
#define jsstrinlines_h___
10
#include "mozilla/Attributes.h"
15
#include "jscntxtinlines.h"
16
#include "jsgcinlines.h"
17
#include "vm/String-inl.h"
25
RopeBuilder(const RopeBuilder &other) MOZ_DELETE;
26
void operator=(const RopeBuilder &other) MOZ_DELETE;
29
RopeBuilder(JSContext *cx)
30
: cx(cx), res(cx, cx->runtime->emptyString)
33
inline bool append(HandleString str) {
34
res = js_ConcatStrings(cx, res, str);
38
inline JSString *result() {
43
class StringSegmentRange
46
* If malloc() shows up in any profiles from this vector, we can add a new
47
* StackAllocPolicy which stashes a reusable freed-at-gc buffer in the cx.
49
AutoStringVector stack;
50
Rooted<JSLinearString*> cur;
52
bool settle(JSString *str) {
53
while (str->isRope()) {
54
JSRope &rope = str->asRope();
55
if (!stack.append(rope.rightChild()))
57
str = rope.leftChild();
59
cur = &str->asLinear();
64
StringSegmentRange(JSContext *cx)
68
JS_WARN_UNUSED_RESULT bool init(JSString *str) {
69
JS_ASSERT(stack.empty());
77
JSLinearString *front() const {
78
JS_ASSERT(!cur->isRope());
82
JS_WARN_UNUSED_RESULT bool popFront() {
88
return settle(stack.popCopy());
93
* Return s advanced past any Unicode white space characters.
95
static inline const jschar *
96
SkipSpace(const jschar *s, const jschar *end)
100
while (s < end && unicode::IsSpace(*s))
107
* Return less than, equal to, or greater than zero depending on whether
108
* s1 is less than, equal to, or greater than s2.
111
CompareChars(const jschar *s1, size_t l1, const jschar *s2, size_t l2, int32_t *result)
113
size_t n = Min(l1, l2);
114
for (size_t i = 0; i < n; i++) {
115
if (int32_t cmp = s1[i] - s2[i]) {
121
*result = (int32_t)(l1 - l2);
127
#endif /* jsstrinlines_h___ */