From 32761a6cee1d0dee366b885b7b9c777e67885688 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Sun, 10 Apr 2016 09:28:39 +0000 Subject: webkitgtk-2.4.11 --- Source/JavaScriptCore/assembler/AssemblerBuffer.h | 118 +++++++--------------- 1 file changed, 35 insertions(+), 83 deletions(-) (limited to 'Source/JavaScriptCore/assembler/AssemblerBuffer.h') 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(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(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 + void putIntegral(IntegralType value) + { + ensureSpace(sizeof(IntegralType)); + putIntegralUnchecked(value); + } + + template + void putIntegralUnchecked(IntegralType value) + { + ASSERT(isAvailable(sizeof(IntegralType))); + *reinterpret_cast_ptr(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 - void putIntegral(IntegralType value) - { - unsigned nextIndex = m_index + sizeof(IntegralType); - if (UNLIKELY(nextIndex > m_storage.capacity())) - grow(); - ASSERT(isAvailable(sizeof(IntegralType))); - *reinterpret_cast_ptr(m_storage.buffer() + m_index) = value; - m_index = nextIndex; - } - - template - void putIntegralUnchecked(IntegralType value) - { - ASSERT(isAvailable(sizeof(IntegralType))); - *reinterpret_cast_ptr(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 m_storage; + char* m_buffer; + int m_capacity; + int m_index; }; } // namespace JSC -- cgit v1.2.1