webengine/osswebengine/WebCore/platform/AtomicString.cpp
changeset 13 10e98eab6f85
parent 0 dd21522fd290
equal deleted inserted replaced
8:7c90e6132015 13:10e98eab6f85
    36 using KJS::UString;
    36 using KJS::UString;
    37 
    37 
    38 namespace WebCore {
    38 namespace WebCore {
    39 
    39 
    40 static HashSet<StringImpl*>* stringTable;
    40 static HashSet<StringImpl*>* stringTable;
       
    41 static bool initialized = false;
    41 
    42 
    42 struct CStringTranslator 
    43 struct CStringTranslator 
    43 {
    44 {
    44     static unsigned hash(const char* c)
    45     static unsigned hash(const char* c)
    45     {
    46     {
   168     return result;
   169     return result;
   169 }
   170 }
   170 
   171 
   171 void AtomicString::remove(StringImpl* r)
   172 void AtomicString::remove(StringImpl* r)
   172 {
   173 {
   173     stringTable->remove(r);
   174     if( stringTable ) {
       
   175         stringTable->remove(r);
       
   176     }
   174 }
   177 }
   175 
   178 
   176 StringImpl* AtomicString::add(const KJS::Identifier& str)
   179 StringImpl* AtomicString::add(const KJS::Identifier& str)
   177 {
   180 {
   178     return add(reinterpret_cast<const UChar*>(str.data()), str.size());
   181     return add(reinterpret_cast<const UChar*>(str.data()), str.size());
   201 DeprecatedString AtomicString::deprecatedString() const
   204 DeprecatedString AtomicString::deprecatedString() const
   202 {
   205 {
   203     return m_string.deprecatedString();
   206     return m_string.deprecatedString();
   204 }
   207 }
   205 
   208 
       
   209 static const char *textAtomStr = "#text";
       
   210 static const char *commentAtomStr = "#comment";
       
   211 static const char *starAtomStr = "*";
       
   212 
   206 DEFINE_GLOBAL(AtomicString, nullAtom)
   213 DEFINE_GLOBAL(AtomicString, nullAtom)
   207 DEFINE_GLOBAL(AtomicString, emptyAtom, "")
   214 DEFINE_GLOBAL(AtomicString, emptyAtom, "")
   208 DEFINE_GLOBAL(AtomicString, textAtom, "#text")
   215 DEFINE_GLOBAL(AtomicString, textAtom, textAtomStr)
   209 DEFINE_GLOBAL(AtomicString, commentAtom, "#comment")
   216 DEFINE_GLOBAL(AtomicString, commentAtom, commentAtomStr)
   210 DEFINE_GLOBAL(AtomicString, starAtom, "*")
   217 DEFINE_GLOBAL(AtomicString, starAtom, starAtomStr)
   211 
   218 
   212 void AtomicString::init()
   219 void AtomicString::init()
   213 {
   220 {
   214     static bool initialized;
       
   215     if (!initialized) {
   221     if (!initialized) {
   216         stringTable = new HashSet<StringImpl*>;
   222         stringTable = new HashSet<StringImpl*>;
   217 
   223 
   218         // Use placement new to initialize the globals.
   224         // Use placement new to initialize the globals.
   219         new ((void*)&nullAtom) AtomicString;
   225         new ((void*)&nullAtom) AtomicString;
   220         new ((void*)&emptyAtom) AtomicString("");
   226         new ((void*)&emptyAtom) AtomicString("");
   221         new ((void*)&textAtom) AtomicString("#text");
   227         new ((void*)&textAtom) AtomicString(textAtomStr);
   222         new ((void*)&commentAtom) AtomicString("#comment");
   228         new ((void*)&commentAtom) AtomicString(commentAtomStr);
   223         new ((void*)&starAtom) AtomicString("*");
   229         new ((void*)&starAtom) AtomicString(starAtomStr);
   224 
   230 
   225         initialized = true;
   231         initialized = true;
   226     }
   232     }
   227 }
   233 }
   228 
   234 
   229 }
   235 void AtomicString::remove()
       
   236 {
       
   237     // Cleanup the string table array
       
   238     if( stringTable )
       
   239         {
       
   240         stringTable->clear();
       
   241         delete stringTable;
       
   242         stringTable = NULL;
       
   243         }
       
   244 	textAtomStr = "";
       
   245 	commentAtomStr = "";
       
   246 	starAtomStr = "";
       
   247     initialized = false; 
       
   248 }
       
   249 
       
   250 }