| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 void* data() const { return m_holder ? m_holder->data() : nullptr; } | 66 void* data() const { return m_holder ? m_holder->data() : nullptr; } |
| 67 unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0
; } | 67 unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0
; } |
| 68 bool isShared() const { return m_holder ? m_holder->isShared() : false; } | 68 bool isShared() const { return m_holder ? m_holder->isShared() : false; } |
| 69 | 69 |
| 70 void transfer(ArrayBufferContents& other); | 70 void transfer(ArrayBufferContents& other); |
| 71 void shareWith(ArrayBufferContents& other); | 71 void shareWith(ArrayBufferContents& other); |
| 72 void copyTo(ArrayBufferContents& other); | 72 void copyTo(ArrayBufferContents& other); |
| 73 | 73 |
| 74 static void allocateMemory(size_t, InitializationPolicy, void*&); | 74 static void allocateMemory(size_t, InitializationPolicy, void*&); |
| 75 static void allocateMemoryOrNull(size_t, InitializationPolicy, void*&); |
| 75 static void freeMemory(void*, size_t); | 76 static void freeMemory(void*, size_t); |
| 76 static void setAdjustAmoutOfExternalAllocatedMemoryFunction(AdjustAmountOfEx
ternalAllocatedMemoryFunction function) | 77 static void setAdjustAmoutOfExternalAllocatedMemoryFunction(AdjustAmountOfEx
ternalAllocatedMemoryFunction function) |
| 77 { | 78 { |
| 78 ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction); | 79 ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction); |
| 79 s_adjustAmountOfExternalAllocatedMemoryFunction = function; | 80 s_adjustAmountOfExternalAllocatedMemoryFunction = function; |
| 80 } | 81 } |
| 81 | 82 |
| 82 private: | 83 private: |
| 84 static void allocateMemoryWithFlags(size_t, InitializationPolicy, int, void*
&); |
| 83 class DataHolder : public ThreadSafeRefCounted<DataHolder> { | 85 class DataHolder : public ThreadSafeRefCounted<DataHolder> { |
| 84 WTF_MAKE_NONCOPYABLE(DataHolder); | 86 WTF_MAKE_NONCOPYABLE(DataHolder); |
| 85 public: | 87 public: |
| 86 DataHolder(); | 88 DataHolder(); |
| 87 ~DataHolder(); | 89 ~DataHolder(); |
| 88 | 90 |
| 89 void allocateNew(unsigned sizeInBytes, SharingType isShared, Initializat
ionPolicy); | 91 void allocateNew(unsigned sizeInBytes, SharingType isShared, Initializat
ionPolicy); |
| 90 void adopt(void* data, unsigned sizeInBytes, SharingType isShared); | 92 void adopt(void* data, unsigned sizeInBytes, SharingType isShared); |
| 91 void copyMemoryTo(DataHolder& other); | 93 void copyMemoryTo(DataHolder& other); |
| 92 | 94 |
| 93 void* data() const { return m_data; } | 95 void* data() const { return m_data; } |
| 94 unsigned sizeInBytes() const { return m_sizeInBytes; } | 96 unsigned sizeInBytes() const { return m_sizeInBytes; } |
| 95 bool isShared() const { return m_isShared == Shared; } | 97 bool isShared() const { return m_isShared == Shared; } |
| 96 | 98 |
| 97 private: | 99 private: |
| 98 void* m_data; | 100 void* m_data; |
| 99 unsigned m_sizeInBytes; | 101 unsigned m_sizeInBytes; |
| 100 SharingType m_isShared; | 102 SharingType m_isShared; |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 RefPtr<DataHolder> m_holder; | 105 RefPtr<DataHolder> m_holder; |
| 104 static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExterna
lAllocatedMemoryFunction; | 106 static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExterna
lAllocatedMemoryFunction; |
| 105 }; | 107 }; |
| 106 | 108 |
| 107 } // namespace WTF | 109 } // namespace WTF |
| 108 | 110 |
| 109 #endif // ArrayBufferContents_h | 111 #endif // ArrayBufferContents_h |
| OLD | NEW |