Changeset 44145 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- May 25, 2009, 9:21:32 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.h
r43856 r44145 2 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 3 3 * 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. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 28 28 #include <string.h> 29 29 #include <wtf/Assertions.h> 30 #include <wtf/CrossThreadRefCounted.h> 31 #include <wtf/OwnFastMallocPtr.h> 30 32 #include <wtf/PassRefPtr.h> 31 33 #include <wtf/PtrAndFlags.h> … … 76 78 77 79 public: 80 typedef CrossThreadRefCounted<OwnFastMallocPtr<UChar> > SharedUChar; 78 81 struct BaseString; 79 82 struct Rep : Noncopyable { … … 102 105 static PassRefPtr<Rep> createFromUTF8(const char*); 103 106 107 // Uses SharedUChar to have joint ownership over the UChar*. 108 static PassRefPtr<Rep> share(UChar*, int, PassRefPtr<SharedUChar>); 109 104 110 void destroy(); 105 111 … … 146 152 147 153 protected: 148 // constructor for use by BaseString subclass; they are their own bases154 // Constructor for use by BaseString subclass; they use the union with m_baseString for another purpose. 149 155 Rep(int length) 150 156 : offset(0) … … 152 158 , rc(1) 153 159 , _hash(0) 154 , m_baseString( static_cast<BaseString*>(this))160 , m_baseString(0) 155 161 { 156 162 } … … 166 172 } 167 173 168 169 BaseString* m_baseString; 174 union { 175 // If !baseIsSelf() 176 BaseString* m_baseString; 177 // If baseIsSelf() 178 SharedUChar* m_sharedBuffer; 179 }; 170 180 171 181 private: … … 181 191 182 192 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 } 184 203 185 204 // potentially shared data. … … 205 224 checkConsistency(); 206 225 } 226 227 bool slowIsBufferReadOnly(); 207 228 208 229 friend struct Rep; … … 454 475 inline UString::BaseString* UString::Rep::baseString() 455 476 { 456 return m_baseString;477 return !baseIsSelf() ? m_baseString : reinterpret_cast<BaseString*>(this) ; 457 478 } 458 479 459 480 inline const UString::BaseString* UString::Rep::baseString() const 460 481 { 461 return m_baseString;482 return const_cast<Rep*>(this)->baseString(); 462 483 } 463 484
Note:
See TracChangeset
for help on using the changeset viewer.