Changeset 100202 in webkit


Ignore:
Timestamp:
Nov 14, 2011, 3:51:06 PM (14 years ago)
Author:
msaboff@apple.com
Message:

Towards 8 bit strings - Add 8 bit handling to JSString Ropes
https://bugs.webkit.org/show_bug.cgi?id=72317

Added bit to track that a rope is made up of all 8 bit fibers.
Created an 8 bit path (fast and slow cases) to handle 8 bit
only ropes.

Reviewed by Oliver Hunt.

  • runtime/JSString.cpp:

(JSC::JSString::resolveRope):
(JSC::JSString::resolveRopeSlowCase8):
(JSC::JSString::resolveRopeSlowCase16):

  • runtime/JSString.h:

(JSC::RopeBuilder::finishCreation):
(JSC::RopeBuilder::is8Bit):
(JSC::jsSubstring8):

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r100200 r100202  
     12011-11-14  Michael Saboff  <msaboff@apple.com>
     2
     3        Towards 8 bit strings - Add 8 bit handling to JSString Ropes
     4        https://bugs.webkit.org/show_bug.cgi?id=72317
     5
     6        Added bit to track that a rope is made up of all 8 bit fibers.
     7        Created an 8 bit path (fast and slow cases) to handle 8 bit
     8        only ropes.
     9
     10        Reviewed by Oliver Hunt.
     11
     12        * runtime/JSString.cpp:
     13        (JSC::JSString::resolveRope):
     14        (JSC::JSString::resolveRopeSlowCase8):
     15        (JSC::JSString::resolveRopeSlowCase16):
     16        * runtime/JSString.h:
     17        (JSC::RopeBuilder::finishCreation):
     18        (JSC::RopeBuilder::is8Bit):
     19        (JSC::jsSubstring8):
     20
    1212011-11-14  Geoffrey Garen  <ggaren@apple.com>
    222
  • trunk/Source/JavaScriptCore/runtime/JSString.cpp

    r100006 r100202  
    6363    ASSERT(isRope());
    6464
     65    if (is8Bit()) {
     66        LChar* buffer;
     67        if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer))
     68            m_value = newImpl;
     69        else {
     70            outOfMemory(exec);
     71            return;
     72        }
     73
     74        for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) {
     75            if (m_fibers[i]->isRope())
     76                return resolveRopeSlowCase(exec, buffer);
     77        }
     78
     79        LChar* position = buffer;
     80        for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) {
     81            StringImpl* string = m_fibers[i]->m_value.impl();
     82            unsigned length = string->length();
     83            StringImpl::copyChars(position, string->characters8(), length);
     84            position += length;
     85            m_fibers[i].clear();
     86        }
     87        ASSERT((buffer + m_length) == position);
     88        ASSERT(!isRope());
     89
     90        return;
     91    }
     92
    6593    UChar* buffer;
    6694    if (PassRefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer))
     
    80108        StringImpl* string = m_fibers[i]->m_value.impl();
    81109        unsigned length = string->length();
    82         StringImpl::copyChars(position, string->characters16(), length);
     110        StringImpl::copyChars(position, string->characters(), length);
    83111        position += length;
    84112        m_fibers[i].clear();
     
    88116}
    89117
    90 // Overview: this methods converts a JSString from holding a string in rope form
     118// Overview: These functions convert a JSString from holding a string in rope form
    91119// down to a simple UString representation.  It does so by building up the string
    92120// backwards, since we want to avoid recursion, we expect that the tree structure
     
    98126// only fill the queue with the number of substrings at any given level in a
    99127// rope-of-ropes.)   
    100 void JSString::resolveRopeSlowCase(ExecState* exec, UChar* buffer) const
     128void JSString::resolveRopeSlowCase(ExecState* exec, LChar* buffer) const
    101129{
    102130    UNUSED_PARAM(exec);
    103131
    104     UChar* position = buffer + m_length; // We will be working backwards over the rope.
     132    LChar* position = buffer + m_length; // We will be working backwards over the rope.
    105133    Vector<JSString*, 32> workQueue; // Putting strings into a Vector is only OK because there are no GC points in this method.
    106134   
     
    124152        unsigned length = string->length();
    125153        position -= length;
    126         StringImpl::copyChars(position, string->characters16(), length);
     154        StringImpl::copyChars(position, string->characters8(), length);
     155    }
     156
     157    ASSERT(buffer == position);
     158    ASSERT(!isRope());
     159}
     160
     161void JSString::resolveRopeSlowCase(ExecState* exec, UChar* buffer) const
     162{
     163    UNUSED_PARAM(exec);
     164
     165    UChar* position = buffer + m_length; // We will be working backwards over the rope.
     166    Vector<JSString*, 32> workQueue; // These strings are kept alive by the parent rope, so using a Vector is OK.
     167
     168    for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i)
     169        workQueue.append(m_fibers[i].get());
     170
     171    while (!workQueue.isEmpty()) {
     172        JSString* currentFiber = workQueue.last();
     173        workQueue.removeLast();
     174
     175        if (currentFiber->isRope()) {
     176            for (size_t i = 0; i < s_maxInternalRopeLength && currentFiber->m_fibers[i]; ++i)
     177                workQueue.append(currentFiber->m_fibers[i].get());
     178            continue;
     179        }
     180
     181        StringImpl* string = static_cast<StringImpl*>(currentFiber->m_value.impl());
     182        unsigned length = string->length();
     183        position -= length;
     184        StringImpl::copyChars(position, string->characters(), length);
    127185    }
    128186
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r99754 r100202  
    2323#ifndef JSString_h
    2424#define JSString_h
    25 
    2625#include "CallFrame.h"
    2726#include "CommonIdentifiers.h"
     
    8685                m_jsString->m_fibers[m_index++].set(m_globalData, m_jsString, jsString);
    8786                m_jsString->m_length += jsString->m_length;
     87                m_jsString->m_is8Bit = m_jsString->m_is8Bit && jsString->m_is8Bit;
    8888            }
    8989
     
    128128            Base::finishCreation(globalData);
    129129            m_length = length;
     130            m_is8Bit = m_value.impl()->is8Bit();
    130131        }
    131132
     
    135136            Base::finishCreation(globalData);
    136137            m_length = length;
     138            m_is8Bit = m_value.impl()->is8Bit();
    137139            Heap::heap(this)->reportExtraMemoryCost(cost);
    138140        }
     
    142144            Base::finishCreation(globalData);
    143145            m_length = s1->length() + s2->length();
     146            m_is8Bit = (s1->is8Bit() && s2->is8Bit());
    144147            m_fibers[0].set(globalData, this, s1);
    145148            m_fibers[1].set(globalData, this, s2);
     
    150153            Base::finishCreation(globalData);
    151154            m_length = s1->length() + s2->length() + s3->length();
     155            m_is8Bit = (s1->is8Bit() && s2->is8Bit() &&  s3->is8Bit());
    152156            m_fibers[0].set(globalData, this, s1);
    153157            m_fibers[1].set(globalData, this, s2);
     
    245249
    246250        void resolveRope(ExecState*) const;
     251        void resolveRopeSlowCase(ExecState*, LChar*) const;
    247252        void resolveRopeSlowCase(ExecState*, UChar*) const;
    248253        void outOfMemory(ExecState*) const;
     
    257262
    258263        // A string is represented either by a UString or a rope of fibers.
     264        bool m_is8Bit : 1;
    259265        unsigned m_length;
    260266        mutable UString m_value;
     
    262268
    263269        bool isRope() const { return m_value.isNull(); }
     270        bool is8Bit() const { return m_is8Bit; }
    264271        UString& string() { ASSERT(!isRope()); return m_value; }
    265272
Note: See TracChangeset for help on using the changeset viewer.