#ifndef SmallStrings_h
#define SmallStrings_h
#include "UString.h"
#include <wtf/FixedArray.h>
#include <wtf/OwnPtr.h>
namespace JSC {
class HeapRootVisitor;
class JSGlobalData;
class JSString;
class MarkStack;
class SmallStringsStorage;
typedef MarkStack SlotVisitor;
static const unsigned maxSingleCharacterString = 0xFF;
class SmallStrings {
WTF_MAKE_NONCOPYABLE(SmallStrings);
public:
SmallStrings();
~SmallStrings();
JSString* emptyString(JSGlobalData* globalData)
{
if (!m_emptyString)
createEmptyString(globalData);
return m_emptyString;
}
JSString* singleCharacterString(JSGlobalData* globalData, unsigned char character)
{
if (!m_singleCharacterStrings[character])
createSingleCharacterString(globalData, character);
return m_singleCharacterStrings[character];
}
StringImpl* singleCharacterStringRep(unsigned char character);
void visitChildren(HeapRootVisitor&);
void clear();
unsigned count() const;
JSString** singleCharacterStrings() { return &m_singleCharacterStrings[0]; }
private:
static const unsigned singleCharacterStringCount = maxSingleCharacterString + 1;
void createEmptyString(JSGlobalData*);
void createSingleCharacterString(JSGlobalData*, unsigned char);
JSString* m_emptyString;
JSString* m_singleCharacterStrings[singleCharacterStringCount];
OwnPtr<SmallStringsStorage> m_storage;
};
}
#endif // SmallStrings_h