| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "pdf/chunk_stream.h" | 5 #include "pdf/chunk_stream.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #define __STDC_LIMIT_MACROS | 10 #define __STDC_LIMIT_MACROS |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 chunks_.clear(); | 28 chunks_.clear(); |
| 29 data_.clear(); | 29 data_.clear(); |
| 30 stream_size_ = 0; | 30 stream_size_ = 0; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void ChunkStream::Preallocate(size_t stream_size) { | 33 void ChunkStream::Preallocate(size_t stream_size) { |
| 34 data_.reserve(stream_size); | 34 data_.reserve(stream_size); |
| 35 stream_size_ = stream_size; | 35 stream_size_ = stream_size; |
| 36 } | 36 } |
| 37 | 37 |
| 38 size_t ChunkStream::GetSize() { | 38 size_t ChunkStream::GetSize() const { |
| 39 return data_.size(); | 39 return data_.size(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool ChunkStream::WriteData(size_t offset, void* buffer, size_t size) { | 42 bool ChunkStream::WriteData(size_t offset, void* buffer, size_t size) { |
| 43 if (SIZE_MAX - size < offset) | 43 if (SIZE_MAX - size < offset) |
| 44 return false; | 44 return false; |
| 45 | 45 |
| 46 if (data_.size() < offset + size) | 46 if (data_.size() < offset + size) |
| 47 data_.resize(offset + size); | 47 data_.resize(offset + size); |
| 48 | 48 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 size_t ChunkStream::GetLastMissingByteInInterval(size_t offset) const { | 166 size_t ChunkStream::GetLastMissingByteInInterval(size_t offset) const { |
| 167 if (chunks_.empty()) | 167 if (chunks_.empty()) |
| 168 return stream_size_ - 1; | 168 return stream_size_ - 1; |
| 169 std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset); | 169 std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset); |
| 170 if (it == chunks_.end()) | 170 if (it == chunks_.end()) |
| 171 return stream_size_ - 1; | 171 return stream_size_ - 1; |
| 172 return it->first - 1; | 172 return it->first - 1; |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace chrome_pdf | 175 } // namespace chrome_pdf |
| OLD | NEW |