| 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 22 matching lines...) Expand all Loading... |
| 33 #undef SHARED_BUFFER_STATS | 33 #undef SHARED_BUFFER_STATS |
| 34 | 34 |
| 35 #ifdef SHARED_BUFFER_STATS | 35 #ifdef SHARED_BUFFER_STATS |
| 36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "public/platform/WebTraceLocation.h" | 37 #include "public/platform/WebTraceLocation.h" |
| 38 #include "wtf/DataLog.h" | 38 #include "wtf/DataLog.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 STATIC_CONST_MEMBER_DEFINITION const unsigned SharedBuffer::kSegmentSize; | |
| 44 | |
| 45 static inline unsigned segmentIndex(unsigned position) | 43 static inline unsigned segmentIndex(unsigned position) |
| 46 { | 44 { |
| 47 return position / SharedBuffer::kSegmentSize; | 45 return position / SharedBuffer::kSegmentSize; |
| 48 } | 46 } |
| 49 | 47 |
| 50 static inline unsigned offsetInSegment(unsigned position) | 48 static inline unsigned offsetInSegment(unsigned position) |
| 51 { | 49 { |
| 52 return position % SharedBuffer::kSegmentSize; | 50 return position % SharedBuffer::kSegmentSize; |
| 53 } | 51 } |
| 54 | 52 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 262 |
| 265 for (;;) { | 263 for (;;) { |
| 266 memcpy(segment, data, bytesToCopy); | 264 memcpy(segment, data, bytesToCopy); |
| 267 if (static_cast<unsigned>(length) == bytesToCopy) | 265 if (static_cast<unsigned>(length) == bytesToCopy) |
| 268 break; | 266 break; |
| 269 | 267 |
| 270 length -= bytesToCopy; | 268 length -= bytesToCopy; |
| 271 data += bytesToCopy; | 269 data += bytesToCopy; |
| 272 segment = allocateSegment(); | 270 segment = allocateSegment(); |
| 273 m_segments.append(segment); | 271 m_segments.append(segment); |
| 274 bytesToCopy = std::min(length, kSegmentSize); | 272 bytesToCopy = std::min(length, static_cast<unsigned>(kSegmentSize)); |
| 275 } | 273 } |
| 276 } | 274 } |
| 277 | 275 |
| 278 void SharedBuffer::append(const Vector<char>& data) | 276 void SharedBuffer::append(const Vector<char>& data) |
| 279 { | 277 { |
| 280 append(data.data(), data.size()); | 278 append(data.data(), data.size()); |
| 281 } | 279 } |
| 282 | 280 |
| 283 void SharedBuffer::clear() | 281 void SharedBuffer::clear() |
| 284 { | 282 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 307 } | 305 } |
| 308 return clone.release(); | 306 return clone.release(); |
| 309 } | 307 } |
| 310 | 308 |
| 311 void SharedBuffer::mergeSegmentsIntoBuffer() const | 309 void SharedBuffer::mergeSegmentsIntoBuffer() const |
| 312 { | 310 { |
| 313 unsigned bufferSize = m_buffer.size(); | 311 unsigned bufferSize = m_buffer.size(); |
| 314 if (m_size > bufferSize) { | 312 if (m_size > bufferSize) { |
| 315 unsigned bytesLeft = m_size - bufferSize; | 313 unsigned bytesLeft = m_size - bufferSize; |
| 316 for (unsigned i = 0; i < m_segments.size(); ++i) { | 314 for (unsigned i = 0; i < m_segments.size(); ++i) { |
| 317 unsigned bytesToCopy = std::min(bytesLeft, kSegmentSize); | 315 unsigned bytesToCopy = std::min(bytesLeft, static_cast<unsigned>(kSe
gmentSize)); |
| 318 m_buffer.append(m_segments[i], bytesToCopy); | 316 m_buffer.append(m_segments[i], bytesToCopy); |
| 319 bytesLeft -= bytesToCopy; | 317 bytesLeft -= bytesToCopy; |
| 320 freeSegment(m_segments[i]); | 318 freeSegment(m_segments[i]); |
| 321 } | 319 } |
| 322 m_segments.clear(); | 320 m_segments.clear(); |
| 323 } | 321 } |
| 324 } | 322 } |
| 325 | 323 |
| 326 unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con
st | 324 unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con
st |
| 327 { | 325 { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 mergeSegmentsIntoBuffer(); | 404 mergeSegmentsIntoBuffer(); |
| 407 m_buffer.unlock(); | 405 m_buffer.unlock(); |
| 408 } | 406 } |
| 409 | 407 |
| 410 bool SharedBuffer::isLocked() const | 408 bool SharedBuffer::isLocked() const |
| 411 { | 409 { |
| 412 return m_buffer.isLocked(); | 410 return m_buffer.isLocked(); |
| 413 } | 411 } |
| 414 | 412 |
| 415 } // namespace blink | 413 } // namespace blink |
| OLD | NEW |