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

Side by Side Diff: third_party/WebKit/Source/wtf/ArrayBuffer.cpp

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 12 matching lines...) Expand all
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "wtf/ArrayBuffer.h" 26 #include "wtf/ArrayBuffer.h"
27 27
28 #include "wtf/ArrayBufferView.h" 28 #include "wtf/ArrayBufferView.h"
29 #include "wtf/RefPtr.h" 29 #include "wtf/RefPtr.h"
30 30
31 namespace WTF { 31 namespace WTF {
32 32
33 bool ArrayBuffer::transfer(ArrayBufferContents& result) 33 bool ArrayBuffer::transfer(ArrayBufferContents& result) {
34 { 34 ASSERT(!isShared());
35 ASSERT(!isShared()); 35 RefPtr<ArrayBuffer> keepAlive(this);
36 RefPtr<ArrayBuffer> keepAlive(this);
37 36
38 if (!m_contents.data()) { 37 if (!m_contents.data()) {
39 result.neuter(); 38 result.neuter();
40 return false; 39 return false;
41 } 40 }
42 41
43 bool allViewsAreNeuterable = true; 42 bool allViewsAreNeuterable = true;
44 for (ArrayBufferView* i = m_firstView; i; i = i->m_nextView) { 43 for (ArrayBufferView* i = m_firstView; i; i = i->m_nextView) {
45 if (!i->isNeuterable()) 44 if (!i->isNeuterable())
46 allViewsAreNeuterable = false; 45 allViewsAreNeuterable = false;
47 } 46 }
48 47
49 if (allViewsAreNeuterable) { 48 if (allViewsAreNeuterable) {
50 m_contents.transfer(result); 49 m_contents.transfer(result);
51 } else { 50 } else {
52 m_contents.copyTo(result); 51 m_contents.copyTo(result);
53 if (!result.data()) 52 if (!result.data())
54 return false; 53 return false;
55 } 54 }
56 55
57 while (m_firstView) { 56 while (m_firstView) {
58 ArrayBufferView* current = m_firstView; 57 ArrayBufferView* current = m_firstView;
59 removeView(current); 58 removeView(current);
60 if (allViewsAreNeuterable || current->isNeuterable()) 59 if (allViewsAreNeuterable || current->isNeuterable())
61 current->neuter(); 60 current->neuter();
62 } 61 }
63 62
64 m_isNeutered = true; 63 m_isNeutered = true;
65 64
66 return true; 65 return true;
67 } 66 }
68 67
69 bool ArrayBuffer::shareContentsWith(ArrayBufferContents& result) 68 bool ArrayBuffer::shareContentsWith(ArrayBufferContents& result) {
70 { 69 ASSERT(isShared());
71 ASSERT(isShared()); 70 RefPtr<ArrayBuffer> keepAlive(this);
72 RefPtr<ArrayBuffer> keepAlive(this);
73 71
74 if (!m_contents.data()) { 72 if (!m_contents.data()) {
75 result.neuter(); 73 result.neuter();
76 return false; 74 return false;
77 } 75 }
78 76
79 m_contents.shareWith(result); 77 m_contents.shareWith(result);
80 return true; 78 return true;
81 } 79 }
82 80
83 void ArrayBuffer::addView(ArrayBufferView* view) 81 void ArrayBuffer::addView(ArrayBufferView* view) {
84 { 82 view->m_buffer = this;
85 view->m_buffer = this; 83 view->m_prevView = 0;
86 view->m_prevView = 0; 84 view->m_nextView = m_firstView;
87 view->m_nextView = m_firstView; 85 if (m_firstView)
88 if (m_firstView) 86 m_firstView->m_prevView = view;
89 m_firstView->m_prevView = view; 87 m_firstView = view;
90 m_firstView = view;
91 } 88 }
92 89
93 void ArrayBuffer::removeView(ArrayBufferView* view) 90 void ArrayBuffer::removeView(ArrayBufferView* view) {
94 { 91 ASSERT(this == view->m_buffer);
95 ASSERT(this == view->m_buffer); 92 if (view->m_nextView)
96 if (view->m_nextView) 93 view->m_nextView->m_prevView = view->m_prevView;
97 view->m_nextView->m_prevView = view->m_prevView; 94 if (view->m_prevView)
98 if (view->m_prevView) 95 view->m_prevView->m_nextView = view->m_nextView;
99 view->m_prevView->m_nextView = view->m_nextView; 96 if (m_firstView == view)
100 if (m_firstView == view) 97 m_firstView = view->m_nextView;
101 m_firstView = view->m_nextView; 98 view->m_prevView = view->m_nextView = 0;
102 view->m_prevView = view->m_nextView = 0;
103 } 99 }
104
105 } 100 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayBuffer.h ('k') | third_party/WebKit/Source/wtf/ArrayBufferBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698