Title: [165265] trunk/Source/_javascript_Core
- Revision
- 165265
- Author
- mhahnenb...@apple.com
- Date
- 2014-03-07 09:13:38 -0800 (Fri, 07 Mar 2014)
Log Message
Use OwnPtr in StructureIDTable
https://bugs.webkit.org/show_bug.cgi?id=129828
Reviewed by Geoffrey Garen.
This reduces the amount of boilerplate and fixes a memory leak.
* runtime/StructureIDTable.cpp:
(JSC::StructureIDTable::StructureIDTable):
(JSC::StructureIDTable::resize):
(JSC::StructureIDTable::flushOldTables):
(JSC::StructureIDTable::allocateID):
(JSC::StructureIDTable::deallocateID):
* runtime/StructureIDTable.h:
(JSC::StructureIDTable::table):
(JSC::StructureIDTable::get):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (165264 => 165265)
--- trunk/Source/_javascript_Core/ChangeLog 2014-03-07 17:03:51 UTC (rev 165264)
+++ trunk/Source/_javascript_Core/ChangeLog 2014-03-07 17:13:38 UTC (rev 165265)
@@ -1,3 +1,22 @@
+2014-03-07 Mark Hahnenberg <mhahnenb...@apple.com>
+
+ Use OwnPtr in StructureIDTable
+ https://bugs.webkit.org/show_bug.cgi?id=129828
+
+ Reviewed by Geoffrey Garen.
+
+ This reduces the amount of boilerplate and fixes a memory leak.
+
+ * runtime/StructureIDTable.cpp:
+ (JSC::StructureIDTable::StructureIDTable):
+ (JSC::StructureIDTable::resize):
+ (JSC::StructureIDTable::flushOldTables):
+ (JSC::StructureIDTable::allocateID):
+ (JSC::StructureIDTable::deallocateID):
+ * runtime/StructureIDTable.h:
+ (JSC::StructureIDTable::table):
+ (JSC::StructureIDTable::get):
+
2014-03-07 Andrew Trick <atr...@apple.com>
FLT should call fmod directly on platforms where LLVM cannot relocate the libcall
Modified: trunk/Source/_javascript_Core/runtime/StructureIDTable.cpp (165264 => 165265)
--- trunk/Source/_javascript_Core/runtime/StructureIDTable.cpp 2014-03-07 17:03:51 UTC (rev 165264)
+++ trunk/Source/_javascript_Core/runtime/StructureIDTable.cpp 2014-03-07 17:13:38 UTC (rev 165265)
@@ -29,12 +29,13 @@
#include <limits.h>
#include <wtf/Atomics.h>
#include <wtf/DataLog.h>
+#include <wtf/PassOwnPtr.h>
namespace JSC {
StructureIDTable::StructureIDTable()
: m_firstFreeOffset(0)
- , m_table(new StructureOrOffset[s_initialSize])
+ , m_table(adoptPtr(new StructureOrOffset[s_initialSize]))
, m_size(0)
, m_capacity(s_initialSize)
{
@@ -43,28 +44,22 @@
allocateID(0);
}
-StructureIDTable::~StructureIDTable()
-{
- delete [] m_table;
-}
-
void StructureIDTable::resize(size_t newCapacity)
{
// Create the new table.
- StructureOrOffset* newTable = new StructureOrOffset[newCapacity];
+ OwnPtr<StructureOrOffset> newTable = adoptPtr(new StructureOrOffset[newCapacity]);
// Copy the contents of the old table to the new table.
- memcpy(newTable, m_table, m_capacity * sizeof(StructureOrOffset));
+ memcpy(newTable.get(), table(), m_capacity * sizeof(StructureOrOffset));
// Store fence to make sure we've copied everything before doing the swap.
WTF::storeStoreFence();
// Swap the old and new tables.
- StructureOrOffset* oldTable = m_table;
- m_table = newTable;
+ swap(m_table, newTable);
// Put the old table (now labeled as new) into the list of old tables.
- m_oldTables.append(oldTable);
+ m_oldTables.append(newTable.release());
// Update the capacity.
m_capacity = newCapacity;
@@ -72,8 +67,6 @@
void StructureIDTable::flushOldTables()
{
- for (unsigned i = 0; i < m_oldTables.size(); ++i)
- delete [] m_oldTables[i];
m_oldTables.clear();
}
@@ -95,7 +88,7 @@
}
StructureID result = m_size;
- m_table[result] = newEntry;
+ table()[result] = newEntry;
m_size++;
return result;
}
@@ -103,8 +96,8 @@
ASSERT(m_firstFreeOffset != s_unusedID);
StructureID result = m_firstFreeOffset;
- m_firstFreeOffset = m_table[m_firstFreeOffset].offset;
- m_table[result].structure = structure;
+ m_firstFreeOffset = table()[m_firstFreeOffset].offset;
+ table()[result].structure = structure;
return result;
#else
return structure;
@@ -115,8 +108,8 @@
{
#if USE(JSVALUE64)
ASSERT(structureID != s_unusedID);
- RELEASE_ASSERT(m_table[structureID].structure == structure);
- m_table[structureID].offset = m_firstFreeOffset;
+ RELEASE_ASSERT(table()[structureID].structure == structure);
+ table()[structureID].offset = m_firstFreeOffset;
m_firstFreeOffset = structureID;
#else
UNUSED_PARAM(structure);
Modified: trunk/Source/_javascript_Core/runtime/StructureIDTable.h (165264 => 165265)
--- trunk/Source/_javascript_Core/runtime/StructureIDTable.h 2014-03-07 17:03:51 UTC (rev 165264)
+++ trunk/Source/_javascript_Core/runtime/StructureIDTable.h 2014-03-07 17:13:38 UTC (rev 165265)
@@ -27,6 +27,7 @@
#define StructureIDTable_h
#include "UnusedPointer.h"
+#include <wtf/OwnPtr.h>
#include <wtf/Vector.h>
namespace JSC {
@@ -43,7 +44,6 @@
friend class LLIntOffsetsExtractor;
public:
StructureIDTable();
- ~StructureIDTable();
void** base() { return reinterpret_cast<void**>(&m_table); }
@@ -55,7 +55,7 @@
private:
void resize(size_t newCapacity);
-
+
union StructureOrOffset {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -63,12 +63,14 @@
StructureID offset;
};
+ StructureOrOffset* table() const { return m_table.get(); }
+
static const size_t s_initialSize = 256;
- Vector<StructureOrOffset*> m_oldTables;
+ Vector<OwnPtr<StructureOrOffset>> m_oldTables;
uint32_t m_firstFreeOffset;
- StructureOrOffset* m_table;
+ OwnPtr<StructureOrOffset> m_table;
size_t m_size;
size_t m_capacity;
@@ -81,7 +83,7 @@
inline Structure* StructureIDTable::get(StructureID structureID)
{
#if USE(JSVALUE64)
- return m_table[structureID].structure;
+ return table()[structureID].structure;
#else
return structureID;
#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes