summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/assembler/AssemblerBuffer.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/assembler/AssemblerBuffer.h
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/assembler/AssemblerBuffer.h')
-rw-r--r--Source/JavaScriptCore/assembler/AssemblerBuffer.h118
1 files changed, 35 insertions, 83 deletions
diff --git a/Source/JavaScriptCore/assembler/AssemblerBuffer.h b/Source/JavaScriptCore/assembler/AssemblerBuffer.h
index d9546931d..120868d63 100644
--- a/Source/JavaScriptCore/assembler/AssemblerBuffer.h
+++ b/Source/JavaScriptCore/assembler/AssemblerBuffer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2012, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -56,74 +56,27 @@ namespace JSC {
return AssemblerLabel(m_offset + offset);
}
- bool operator==(const AssemblerLabel& other) const { return m_offset == other.m_offset; }
-
uint32_t m_offset;
};
- class AssemblerData {
- public:
- AssemblerData()
- : m_buffer(nullptr)
- , m_capacity(0)
- {
- }
-
- AssemblerData(unsigned initialCapacity)
- {
- m_capacity = initialCapacity;
- m_buffer = static_cast<char*>(fastMalloc(m_capacity));
- }
-
- AssemblerData(AssemblerData&& other)
- {
- m_buffer = other.m_buffer;
- other.m_buffer = nullptr;
- m_capacity = other.m_capacity;
- other.m_capacity = 0;
- }
-
- AssemblerData& operator=(AssemblerData&& other)
- {
- m_buffer = other.m_buffer;
- other.m_buffer = nullptr;
- m_capacity = other.m_capacity;
- other.m_capacity = 0;
- return *this;
- }
-
- ~AssemblerData()
- {
- fastFree(m_buffer);
- }
-
- char* buffer() const { return m_buffer; }
-
- unsigned capacity() const { return m_capacity; }
-
- void grow(unsigned extraCapacity = 0)
- {
- m_capacity = m_capacity + m_capacity / 2 + extraCapacity;
- m_buffer = static_cast<char*>(fastRealloc(m_buffer, m_capacity));
- }
-
- private:
- char* m_buffer;
- unsigned m_capacity;
- };
-
class AssemblerBuffer {
- static const int initialCapacity = 128;
+ static const int inlineCapacity = 128;
public:
AssemblerBuffer()
- : m_storage(initialCapacity)
+ : m_storage(inlineCapacity)
+ , m_buffer(m_storage.begin())
+ , m_capacity(inlineCapacity)
, m_index(0)
{
}
+ ~AssemblerBuffer()
+ {
+ }
+
bool isAvailable(int space)
{
- return m_index + space <= m_storage.capacity();
+ return m_index + space <= m_capacity;
}
void ensureSpace(int space)
@@ -137,6 +90,21 @@ namespace JSC {
return !(m_index & (alignment - 1));
}
+ template<typename IntegralType>
+ void putIntegral(IntegralType value)
+ {
+ ensureSpace(sizeof(IntegralType));
+ putIntegralUnchecked(value);
+ }
+
+ template<typename IntegralType>
+ void putIntegralUnchecked(IntegralType value)
+ {
+ ASSERT(isAvailable(sizeof(IntegralType)));
+ *reinterpret_cast_ptr<IntegralType*>(m_buffer + m_index) = value;
+ m_index += sizeof(IntegralType);
+ }
+
void putByteUnchecked(int8_t value) { putIntegralUnchecked(value); }
void putByte(int8_t value) { putIntegral(value); }
void putShortUnchecked(int16_t value) { putIntegralUnchecked(value); }
@@ -148,7 +116,7 @@ namespace JSC {
void* data() const
{
- return m_storage.buffer();
+ return m_buffer;
}
size_t codeSize() const
@@ -163,45 +131,29 @@ namespace JSC {
unsigned debugOffset() { return m_index; }
- AssemblerData releaseAssemblerData() { return WTFMove(m_storage); }
-
protected:
- template<typename IntegralType>
- void putIntegral(IntegralType value)
- {
- unsigned nextIndex = m_index + sizeof(IntegralType);
- if (UNLIKELY(nextIndex > m_storage.capacity()))
- grow();
- ASSERT(isAvailable(sizeof(IntegralType)));
- *reinterpret_cast_ptr<IntegralType*>(m_storage.buffer() + m_index) = value;
- m_index = nextIndex;
- }
-
- template<typename IntegralType>
- void putIntegralUnchecked(IntegralType value)
- {
- ASSERT(isAvailable(sizeof(IntegralType)));
- *reinterpret_cast_ptr<IntegralType*>(m_storage.buffer() + m_index) = value;
- m_index += sizeof(IntegralType);
- }
-
void append(const char* data, int size)
{
if (!isAvailable(size))
grow(size);
- memcpy(m_storage.buffer() + m_index, data, size);
+ memcpy(m_buffer + m_index, data, size);
m_index += size;
}
void grow(int extraCapacity = 0)
{
- m_storage.grow(extraCapacity);
+ m_capacity += m_capacity / 2 + extraCapacity;
+
+ m_storage.grow(m_capacity);
+ m_buffer = m_storage.begin();
}
private:
- AssemblerData m_storage;
- unsigned m_index;
+ Vector<char, inlineCapacity, UnsafeVectorOverflow> m_storage;
+ char* m_buffer;
+ int m_capacity;
+ int m_index;
};
} // namespace JSC