Ignore:
Timestamp:
May 25, 2009, 9:21:32 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-05-25 David Levin <[email protected]>

Reviewed by Maciej Stachowiak and Oliver Hunt.

https://bugs.webkit.org/show_bug.cgi?id=25126
Allow the buffer underlying UString to be shared.

In order to not grow the underlying size of any structure,
there is a union in the Rep string which holds

+ m_sharedBuffer -- a pointer to the shared ref counted buffer

if the class is BaseString and the buffer is being shared OR

+ m_baseString -- the BaseString if the class is only UString::Rep

but not a UString::BaseString

Ideally, m_sharedBuffer would be a RefPtr, but it cannot be because
it is in a union.

No change in sunspider perf.

  • JavaScriptCore.vcproj/WTF/WTF.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • runtime/UString.cpp: (JSC::UString::Rep::share): (JSC::UString::Rep::destroy): (JSC::UString::BaseString::sharedBuffer): (JSC::UString::BaseString::setSharedBuffer): (JSC::UString::BaseString::slowIsBufferReadOnly): (JSC::expandCapacity): (JSC::UString::Rep::reserveCapacity): (JSC::UString::expandPreCapacity): (JSC::concatenate): (JSC::UString::append):
  • runtime/UString.h: (JSC::UString::Rep::Rep): (JSC::UString::Rep::): (JSC::UString::BaseString::isShared): (JSC::UString::BaseString::isBufferReadOnly): (JSC::UString::Rep::baseString):
  • wtf/CrossThreadRefCounted.h: (WTF::CrossThreadRefCounted::isShared):
  • wtf/OwnFastMallocPtr.h: Added. (WTF::OwnFastMallocPtr::OwnFastMallocPtr): (WTF::OwnFastMallocPtr::~OwnFastMallocPtr): (WTF::OwnFastMallocPtr::get): (WTF::OwnFastMallocPtr::release):

JavaScriptGlue:

2009-05-25 David Levin <[email protected]>

Reviewed by Maciej Stachowiak and Oliver Hunt.

https://bugs.webkit.org/show_bug.cgi?id=25126

Added forwarding headers.

  • ForwardingHeaders/wtf/CrossThreadRefCounted.h: Added.
  • ForwardingHeaders/wtf/OwnFastMallocPtr.h: Added.

WebCore:

2009-05-25 David Levin <[email protected]>

Reviewed by Maciej Stachowiak and Oliver Hunt.

Added forwarding headers.

  • ForwardingHeaders/wtf/CrossThreadRefCounted.h: Added.
  • ForwardingHeaders/wtf/OwnFastMallocPtr.h: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UString.h

    r43856 r44145  
    22 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
    4  *  Copyright (c) 2009, Google Inc. All rights reserved.
     4 *  Copyright (C) 2009 Google Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    2828#include <string.h>
    2929#include <wtf/Assertions.h>
     30#include <wtf/CrossThreadRefCounted.h>
     31#include <wtf/OwnFastMallocPtr.h>
    3032#include <wtf/PassRefPtr.h>
    3133#include <wtf/PtrAndFlags.h>
     
    7678
    7779    public:
     80        typedef CrossThreadRefCounted<OwnFastMallocPtr<UChar> > SharedUChar;
    7881        struct BaseString;
    7982        struct Rep : Noncopyable {
     
    102105            static PassRefPtr<Rep> createFromUTF8(const char*);
    103106
     107            // Uses SharedUChar to have joint ownership over the UChar*.
     108            static PassRefPtr<Rep> share(UChar*, int, PassRefPtr<SharedUChar>);
     109
    104110            void destroy();
    105111
     
    146152
    147153        protected:
    148             // constructor for use by BaseString subclass; they are their own bases
     154            // Constructor for use by BaseString subclass; they use the union with m_baseString for another purpose.
    149155            Rep(int length)
    150156                : offset(0)
     
    152158                , rc(1)
    153159                , _hash(0)
    154                 , m_baseString(static_cast<BaseString*>(this))
     160                , m_baseString(0)
    155161            {
    156162            }
     
    166172            }
    167173
    168 
    169             BaseString* m_baseString;
     174            union {
     175                // If !baseIsSelf()
     176                BaseString* m_baseString;
     177                // If baseIsSelf()
     178                SharedUChar* m_sharedBuffer;
     179            };
    170180
    171181        private:
     
    181191
    182192        struct BaseString : public Rep {
    183             bool isShared() { return rc != 1; }
     193            bool isShared() { return rc != 1 || isBufferReadOnly(); }
     194            void setSharedBuffer(PassRefPtr<SharedUChar>);
     195            SharedUChar* sharedBuffer();
     196
     197            bool isBufferReadOnly()
     198            {
     199                if (!m_sharedBuffer)
     200                    return false;
     201                return slowIsBufferReadOnly();
     202            }
    184203
    185204            // potentially shared data.
     
    205224                checkConsistency();
    206225            }
     226
     227            bool slowIsBufferReadOnly();
    207228
    208229            friend struct Rep;
     
    454475    inline UString::BaseString* UString::Rep::baseString()
    455476    {
    456         return m_baseString;
     477        return !baseIsSelf() ? m_baseString : reinterpret_cast<BaseString*>(this) ;
    457478    }
    458479
    459480    inline const UString::BaseString* UString::Rep::baseString() const
    460481    {
    461         return m_baseString;
     482        return const_cast<Rep*>(this)->baseString();
    462483    }
    463484
Note: See TracChangeset for help on using the changeset viewer.