Changeset 46180 in webkit for trunk/JavaScriptCore/wtf/FastMalloc.h
- Timestamp:
- Jul 21, 2009, 11:13:11 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/FastMalloc.h
r46153 r46180 23 23 24 24 #include "Platform.h" 25 #include "PossiblyNull.h"26 25 #include <stdlib.h> 27 26 #include <new> … … 35 34 void* fastRealloc(void* p, size_t n); 36 35 37 struct TryMallocReturnValue {38 TryMallocReturnValue(void* data)39 : m_data(data)40 {41 }42 ~TryMallocReturnValue() { ASSERT(!m_data); }43 template <typename T> bool getValue(T& data) WARN_UNUSED_RETURN;44 template <typename T> operator PossiblyNull<T>()45 {46 T value;47 getValue(value);48 return PossiblyNull<T>(value);49 }50 private:51 void* m_data;52 };53 54 template <typename T> bool TryMallocReturnValue::getValue(T& data) {55 union u { void* data; T target; } res;56 res.data = m_data;57 data = res.target;58 bool returnValue = !!m_data;59 m_data = 0;60 return returnValue;61 }62 63 36 // These functions return NULL if an allocation fails. 64 TryMallocReturnValuetryFastMalloc(size_t n);65 TryMallocReturnValuetryFastZeroedMalloc(size_t n);66 TryMallocReturnValuetryFastCalloc(size_t n_elements, size_t element_size);67 TryMallocReturnValuetryFastRealloc(void* p, size_t n);37 void* tryFastMalloc(size_t n); 38 void* tryFastZeroedMalloc(size_t n); 39 void* tryFastCalloc(size_t n_elements, size_t element_size); 40 void* tryFastRealloc(void* p, size_t n); 68 41 69 42 void fastFree(void* p);
Note:
See TracChangeset
for help on using the changeset viewer.