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

Side by Side Diff: Source/wtf/ArrayBufferView.h

Issue 1180023002: Inline the only callers of TypedArrayBase::{setRange,zeroRange} (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void setNeuterable(bool flag) { m_isNeuterable = flag; } 73 void setNeuterable(bool flag) { m_isNeuterable = flag; }
74 bool isNeuterable() const { return m_isNeuterable; } 74 bool isNeuterable() const { return m_isNeuterable; }
75 75
76 virtual ~ArrayBufferView(); 76 virtual ~ArrayBufferView();
77 77
78 protected: 78 protected:
79 ArrayBufferView(PassRefPtr<ArrayBuffer>, unsigned byteOffset); 79 ArrayBufferView(PassRefPtr<ArrayBuffer>, unsigned byteOffset);
80 80
81 inline bool setImpl(ArrayBufferView*, unsigned byteOffset); 81 inline bool setImpl(ArrayBufferView*, unsigned byteOffset);
82 82
83 inline bool setRangeImpl(const char* data, size_t dataByteLength, unsigned b yteOffset);
84
85 inline bool zeroRangeImpl(unsigned byteOffset, size_t rangeByteLength);
86
87 // Helper to verify that a given sub-range of an ArrayBuffer is 83 // Helper to verify that a given sub-range of an ArrayBuffer is
88 // within range. 84 // within range.
89 template <typename T> 85 template <typename T>
90 static bool verifySubRange(PassRefPtr<ArrayBuffer> buffer, 86 static bool verifySubRange(PassRefPtr<ArrayBuffer> buffer,
91 unsigned byteOffset, 87 unsigned byteOffset,
92 unsigned numElements) 88 unsigned numElements)
93 { 89 {
94 if (!buffer) 90 if (!buffer)
95 return false; 91 return false;
96 if (sizeof(T) > 1 && byteOffset % sizeof(T)) 92 if (sizeof(T) > 1 && byteOffset % sizeof(T))
(...skipping 28 matching lines...) Expand all
125 || byteOffset + array->byteLength() < byteOffset) { 121 || byteOffset + array->byteLength() < byteOffset) {
126 // Out of range offset or overflow 122 // Out of range offset or overflow
127 return false; 123 return false;
128 } 124 }
129 125
130 char* base = static_cast<char*>(baseAddress()); 126 char* base = static_cast<char*>(baseAddress());
131 memmove(base + byteOffset, array->baseAddress(), array->byteLength()); 127 memmove(base + byteOffset, array->baseAddress(), array->byteLength());
132 return true; 128 return true;
133 } 129 }
134 130
135 bool ArrayBufferView::setRangeImpl(const char* data, size_t dataByteLength, unsi gned byteOffset)
136 {
137 if (byteOffset > byteLength()
138 || byteOffset + dataByteLength > byteLength()
139 || byteOffset + dataByteLength < byteOffset) {
140 // Out of range offset or overflow
141 return false;
142 }
143
144 char* base = static_cast<char*>(baseAddress());
145 memmove(base + byteOffset, data, dataByteLength);
146 return true;
147 }
148
149 bool ArrayBufferView::zeroRangeImpl(unsigned byteOffset, size_t rangeByteLength)
150 {
151 if (byteOffset > byteLength()
152 || byteOffset + rangeByteLength > byteLength()
153 || byteOffset + rangeByteLength < byteOffset) {
154 // Out of range offset or overflow
155 return false;
156 }
157
158 char* base = static_cast<char*>(baseAddress());
159 memset(base + byteOffset, 0, rangeByteLength);
160 return true;
161 }
162
163 } // namespace WTF 131 } // namespace WTF
164 132
165 using WTF::ArrayBufferView; 133 using WTF::ArrayBufferView;
166 134
167 #endif // ArrayBufferView_h 135 #endif // ArrayBufferView_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698