diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/JavaScriptCore/assembler/AssemblerBuffer.h | |
parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/JavaScriptCore/assembler/AssemblerBuffer.h')
-rw-r--r-- | Source/JavaScriptCore/assembler/AssemblerBuffer.h | 116 |
1 files changed, 35 insertions, 81 deletions
diff --git a/Source/JavaScriptCore/assembler/AssemblerBuffer.h b/Source/JavaScriptCore/assembler/AssemblerBuffer.h index 3632a5b6e..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 @@ -59,69 +59,24 @@ namespace JSC { 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) @@ -135,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); } @@ -146,7 +116,7 @@ namespace JSC { void* data() const { - return m_storage.buffer(); + return m_buffer; } size_t codeSize() const @@ -161,45 +131,29 @@ namespace JSC { unsigned debugOffset() { return m_index; } - AssemblerData releaseAssemblerData() { return WTF::move(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 |