Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: Source/wtf/ArrayBufferContents.cpp

Issue 18316003: Revert "Use V8 implementation of ArrayBuffer in Blink." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/ArrayBufferContents.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // FIXME: Why not? The tryFastCalloc function already checks its arguments, 45 // FIXME: Why not? The tryFastCalloc function already checks its arguments,
46 // and will fail if there is any overflow, so why should we include a 46 // and will fail if there is any overflow, so why should we include a
47 // redudant unnecessarily restrictive check here? 47 // redudant unnecessarily restrictive check here?
48 if (numElements) { 48 if (numElements) {
49 unsigned totalSize = numElements * elementByteSize; 49 unsigned totalSize = numElements * elementByteSize;
50 if (totalSize / numElements != elementByteSize) { 50 if (totalSize / numElements != elementByteSize) {
51 m_data = 0; 51 m_data = 0;
52 return; 52 return;
53 } 53 }
54 } 54 }
55 if (allocateMemory(numElements * elementByteSize, policy, m_data)) { 55 bool allocationSucceeded = false;
56 if (policy == ZeroInitialize)
57 allocationSucceeded = WTF::tryFastCalloc(numElements, elementByteSize).g etValue(m_data);
58 else {
59 ASSERT(policy == DontInitialize);
60 allocationSucceeded = WTF::tryFastMalloc(numElements * elementByteSize). getValue(m_data);
61 }
62
63 if (allocationSucceeded) {
56 m_sizeInBytes = numElements * elementByteSize; 64 m_sizeInBytes = numElements * elementByteSize;
57 return; 65 return;
58 } 66 }
59 m_data = 0; 67 m_data = 0;
60 } 68 }
61 69
62 ArrayBufferContents::ArrayBufferContents(void* data, unsigned sizeInBytes)
63 : m_data(data)
64 , m_sizeInBytes(sizeInBytes)
65 , m_deallocationObserver(0) { }
66
67 ArrayBufferContents::~ArrayBufferContents() 70 ArrayBufferContents::~ArrayBufferContents()
68 { 71 {
69 freeMemory(m_data); 72 WTF::fastFree(m_data);
70 clear(); 73 clear();
71 } 74 }
72 75
73 void ArrayBufferContents::clear() 76 void ArrayBufferContents::clear()
74 { 77 {
75 if (m_data && m_deallocationObserver) 78 if (m_data && m_deallocationObserver)
76 m_deallocationObserver->ArrayBufferDeallocated(m_sizeInBytes); 79 m_deallocationObserver->ArrayBufferDeallocated(m_sizeInBytes);
77 m_data = 0; 80 m_data = 0;
78 m_sizeInBytes = 0; 81 m_sizeInBytes = 0;
79 m_deallocationObserver = 0; 82 m_deallocationObserver = 0;
80 } 83 }
81 84
82 void ArrayBufferContents::transfer(ArrayBufferContents& other) 85 void ArrayBufferContents::transfer(ArrayBufferContents& other)
83 { 86 {
84 ASSERT(!other.m_data); 87 ASSERT(!other.m_data);
85 other.m_data = m_data; 88 other.m_data = m_data;
86 other.m_sizeInBytes = m_sizeInBytes; 89 other.m_sizeInBytes = m_sizeInBytes;
87 clear(); 90 clear();
88 } 91 }
89 92
90 bool ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic y, void*& data)
91 {
92 if (policy == ZeroInitialize) {
93 return WTF::tryFastCalloc(size, 1).getValue(data);
94 }
95 ASSERT(policy == DontInitialize);
96 return WTF::tryFastMalloc(size).getValue(data);
97 }
98
99 void ArrayBufferContents::freeMemory(void * data)
100 {
101 WTF::fastFree(data);
102 }
103
104 } // namespace WTF 93 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/ArrayBufferContents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698