| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. 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 19 matching lines...) Expand all Loading... |
| 30 #include "wtf/unicode/Unicode.h" | 30 #include "wtf/unicode/Unicode.h" |
| 31 #include "wtf/unicode/UTF8.h" | 31 #include "wtf/unicode/UTF8.h" |
| 32 | 32 |
| 33 #undef SHARED_BUFFER_STATS | 33 #undef SHARED_BUFFER_STATS |
| 34 | 34 |
| 35 #ifdef SHARED_BUFFER_STATS | 35 #ifdef SHARED_BUFFER_STATS |
| 36 #include "wtf/DataLog.h" | 36 #include "wtf/DataLog.h" |
| 37 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 using namespace std; | |
| 41 | |
| 42 namespace blink { | 40 namespace blink { |
| 43 | 41 |
| 44 static const unsigned segmentSize = 0x1000; | 42 static const unsigned segmentSize = 0x1000; |
| 45 static const unsigned segmentPositionMask = 0x0FFF; | 43 static const unsigned segmentPositionMask = 0x0FFF; |
| 46 | 44 |
| 47 static inline unsigned segmentIndex(unsigned position) | 45 static inline unsigned segmentIndex(unsigned position) |
| 48 { | 46 { |
| 49 return position / segmentSize; | 47 return position / segmentSize; |
| 50 } | 48 } |
| 51 | 49 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 257 } |
| 260 | 258 |
| 261 char* segment; | 259 char* segment; |
| 262 if (!positionInSegment) { | 260 if (!positionInSegment) { |
| 263 segment = allocateSegment(); | 261 segment = allocateSegment(); |
| 264 m_segments.append(segment); | 262 m_segments.append(segment); |
| 265 } else | 263 } else |
| 266 segment = m_segments.last() + positionInSegment; | 264 segment = m_segments.last() + positionInSegment; |
| 267 | 265 |
| 268 unsigned segmentFreeSpace = segmentSize - positionInSegment; | 266 unsigned segmentFreeSpace = segmentSize - positionInSegment; |
| 269 unsigned bytesToCopy = min(length, segmentFreeSpace); | 267 unsigned bytesToCopy = std::min(length, segmentFreeSpace); |
| 270 | 268 |
| 271 for (;;) { | 269 for (;;) { |
| 272 memcpy(segment, data, bytesToCopy); | 270 memcpy(segment, data, bytesToCopy); |
| 273 if (static_cast<unsigned>(length) == bytesToCopy) | 271 if (static_cast<unsigned>(length) == bytesToCopy) |
| 274 break; | 272 break; |
| 275 | 273 |
| 276 length -= bytesToCopy; | 274 length -= bytesToCopy; |
| 277 data += bytesToCopy; | 275 data += bytesToCopy; |
| 278 segment = allocateSegment(); | 276 segment = allocateSegment(); |
| 279 m_segments.append(segment); | 277 m_segments.append(segment); |
| 280 bytesToCopy = min(length, segmentSize); | 278 bytesToCopy = std::min(length, segmentSize); |
| 281 } | 279 } |
| 282 } | 280 } |
| 283 | 281 |
| 284 void SharedBuffer::append(const Vector<char>& data) | 282 void SharedBuffer::append(const Vector<char>& data) |
| 285 { | 283 { |
| 286 append(data.data(), data.size()); | 284 append(data.data(), data.size()); |
| 287 } | 285 } |
| 288 | 286 |
| 289 void SharedBuffer::clear() | 287 void SharedBuffer::clear() |
| 290 { | 288 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 314 return clone.release(); | 312 return clone.release(); |
| 315 } | 313 } |
| 316 | 314 |
| 317 void SharedBuffer::mergeSegmentsIntoBuffer() const | 315 void SharedBuffer::mergeSegmentsIntoBuffer() const |
| 318 { | 316 { |
| 319 unsigned bufferSize = m_buffer.size(); | 317 unsigned bufferSize = m_buffer.size(); |
| 320 if (m_size > bufferSize) { | 318 if (m_size > bufferSize) { |
| 321 m_buffer.reserveCapacity(m_size); | 319 m_buffer.reserveCapacity(m_size); |
| 322 unsigned bytesLeft = m_size - bufferSize; | 320 unsigned bytesLeft = m_size - bufferSize; |
| 323 for (unsigned i = 0; i < m_segments.size(); ++i) { | 321 for (unsigned i = 0; i < m_segments.size(); ++i) { |
| 324 unsigned bytesToCopy = min(bytesLeft, segmentSize); | 322 unsigned bytesToCopy = std::min(bytesLeft, segmentSize); |
| 325 m_buffer.append(m_segments[i], bytesToCopy); | 323 m_buffer.append(m_segments[i], bytesToCopy); |
| 326 bytesLeft -= bytesToCopy; | 324 bytesLeft -= bytesToCopy; |
| 327 freeSegment(m_segments[i]); | 325 freeSegment(m_segments[i]); |
| 328 } | 326 } |
| 329 m_segments.clear(); | 327 m_segments.clear(); |
| 330 } | 328 } |
| 331 } | 329 } |
| 332 | 330 |
| 333 unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con
st | 331 unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con
st |
| 334 { | 332 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 345 someData = m_buffer.data() + position; | 343 someData = m_buffer.data() + position; |
| 346 return consecutiveSize - position; | 344 return consecutiveSize - position; |
| 347 } | 345 } |
| 348 | 346 |
| 349 position -= consecutiveSize; | 347 position -= consecutiveSize; |
| 350 unsigned segments = m_segments.size(); | 348 unsigned segments = m_segments.size(); |
| 351 unsigned maxSegmentedSize = segments * segmentSize; | 349 unsigned maxSegmentedSize = segments * segmentSize; |
| 352 unsigned segment = segmentIndex(position); | 350 unsigned segment = segmentIndex(position); |
| 353 if (segment < segments) { | 351 if (segment < segments) { |
| 354 unsigned bytesLeft = totalSize - consecutiveSize; | 352 unsigned bytesLeft = totalSize - consecutiveSize; |
| 355 unsigned segmentedSize = min(maxSegmentedSize, bytesLeft); | 353 unsigned segmentedSize = std::min(maxSegmentedSize, bytesLeft); |
| 356 | 354 |
| 357 unsigned positionInSegment = offsetInSegment(position); | 355 unsigned positionInSegment = offsetInSegment(position); |
| 358 someData = m_segments[segment] + positionInSegment; | 356 someData = m_segments[segment] + positionInSegment; |
| 359 return segment == segments - 1 ? segmentedSize - position : segmentSize
- positionInSegment; | 357 return segment == segments - 1 ? segmentedSize - position : segmentSize
- positionInSegment; |
| 360 } | 358 } |
| 361 ASSERT_NOT_REACHED(); | 359 ASSERT_NOT_REACHED(); |
| 362 return 0; | 360 return 0; |
| 363 } | 361 } |
| 364 | 362 |
| 365 PassRefPtr<ArrayBuffer> SharedBuffer::getAsArrayBuffer() const | 363 PassRefPtr<ArrayBuffer> SharedBuffer::getAsArrayBuffer() const |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 mergeSegmentsIntoBuffer(); | 412 mergeSegmentsIntoBuffer(); |
| 415 m_buffer.unlock(); | 413 m_buffer.unlock(); |
| 416 } | 414 } |
| 417 | 415 |
| 418 bool SharedBuffer::isLocked() const | 416 bool SharedBuffer::isLocked() const |
| 419 { | 417 { |
| 420 return m_buffer.isLocked(); | 418 return m_buffer.isLocked(); |
| 421 } | 419 } |
| 422 | 420 |
| 423 } // namespace blink | 421 } // namespace blink |
| OLD | NEW |