diff options
author | jln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 02:06:52 +0000 |
---|---|---|
committer | jln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-14 02:06:52 +0000 |
commit | 20553490d852f32afb52e56dd68a8b9ca8ab2d6f (patch) | |
tree | 1c9736fc04975b81fd538cdde3dee942bc9f4fd5 /courgette | |
parent | 684003e2fb896d674c4202edeae9219b7ea167be (diff) | |
download | chromium_src-20553490d852f32afb52e56dd68a8b9ca8ab2d6f.zip chromium_src-20553490d852f32afb52e56dd68a8b9ca8ab2d6f.tar.gz chromium_src-20553490d852f32afb52e56dd68a8b9ca8ab2d6f.tar.bz2 |
Do a giant svn propset svn:eol-style LF on .cc and .h files that
lack this property.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182368 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette')
-rw-r--r-- | courgette/third_party/paged_array.h | 162 |
1 files changed, 81 insertions, 81 deletions
diff --git a/courgette/third_party/paged_array.h b/courgette/third_party/paged_array.h index e9d0299..b12b695 100644 --- a/courgette/third_party/paged_array.h +++ b/courgette/third_party/paged_array.h @@ -1,81 +1,81 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// PagedArray implements an array stored using many fixed-size pages.
-//
-// PagedArray is a work-around to allow large arrays to be allocated when there
-// is too much address space fragmentation for allocating the large arrays as
-// contigous arrays.
-#ifndef COURGETTE_BSDIFF_PAGED_ARRAY_H_
-#define COURGETTE_BSDIFF_PAGED_ARRAY_H_
-
-// For std::nothrow:
-#include <new>
-
-#include "base/basictypes.h"
-
-namespace courgette {
-
-// PagedArray implements an array stored using many fixed-size pages.
-template<typename T>
-class PagedArray {
- enum {
- // Page size in elements. Page size of 2^18 * sizeof(T) is 1MB for T = int.
- kLogPageSize = 18,
- kPageSize = 1 << kLogPageSize
- };
-
- public:
- PagedArray() : pages_(NULL), page_count_(0) {}
-
- ~PagedArray() { clear(); }
-
- T& operator[](size_t i) {
- size_t page = i >> kLogPageSize;
- size_t offset = i & (kPageSize - 1);
- // It is tempting to add a DCHECK(page < page_count_), but that makes
- // bsdiff_create run 2x slower (even when compiled optimized.)
- return pages_[page][offset];
- }
-
- // Allocates storage for |size| elements. Returns true on success and false if
- // allocation fails.
- bool Allocate(size_t size) {
- clear();
- size_t pages_needed = (size + kPageSize - 1) >> kLogPageSize;
- pages_ = new(std::nothrow) T*[pages_needed];
- if (pages_ == NULL)
- return false;
-
- for (page_count_ = 0; page_count_ < pages_needed; ++page_count_) {
- T* block = new(std::nothrow) T[kPageSize];
- if (block == NULL) {
- clear();
- return false;
- }
- pages_[page_count_] = block;
- }
- return true;
- }
-
- // Releases all storage. May be called more than once.
- void clear() {
- if (pages_ != NULL) {
- while (page_count_ != 0) {
- --page_count_;
- delete[] pages_[page_count_];
- }
- delete[] pages_;
- pages_ = NULL;
- }
- }
-
- private:
- T** pages_;
- size_t page_count_;
-
- DISALLOW_COPY_AND_ASSIGN(PagedArray);
-};
-} // namespace
-#endif // COURGETTE_BSDIFF_PAGED_ARRAY_H_
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// PagedArray implements an array stored using many fixed-size pages. +// +// PagedArray is a work-around to allow large arrays to be allocated when there +// is too much address space fragmentation for allocating the large arrays as +// contigous arrays. +#ifndef COURGETTE_BSDIFF_PAGED_ARRAY_H_ +#define COURGETTE_BSDIFF_PAGED_ARRAY_H_ + +// For std::nothrow: +#include <new> + +#include "base/basictypes.h" + +namespace courgette { + +// PagedArray implements an array stored using many fixed-size pages. +template<typename T> +class PagedArray { + enum { + // Page size in elements. Page size of 2^18 * sizeof(T) is 1MB for T = int. + kLogPageSize = 18, + kPageSize = 1 << kLogPageSize + }; + + public: + PagedArray() : pages_(NULL), page_count_(0) {} + + ~PagedArray() { clear(); } + + T& operator[](size_t i) { + size_t page = i >> kLogPageSize; + size_t offset = i & (kPageSize - 1); + // It is tempting to add a DCHECK(page < page_count_), but that makes + // bsdiff_create run 2x slower (even when compiled optimized.) + return pages_[page][offset]; + } + + // Allocates storage for |size| elements. Returns true on success and false if + // allocation fails. + bool Allocate(size_t size) { + clear(); + size_t pages_needed = (size + kPageSize - 1) >> kLogPageSize; + pages_ = new(std::nothrow) T*[pages_needed]; + if (pages_ == NULL) + return false; + + for (page_count_ = 0; page_count_ < pages_needed; ++page_count_) { + T* block = new(std::nothrow) T[kPageSize]; + if (block == NULL) { + clear(); + return false; + } + pages_[page_count_] = block; + } + return true; + } + + // Releases all storage. May be called more than once. + void clear() { + if (pages_ != NULL) { + while (page_count_ != 0) { + --page_count_; + delete[] pages_[page_count_]; + } + delete[] pages_; + pages_ = NULL; + } + } + + private: + T** pages_; + size_t page_count_; + + DISALLOW_COPY_AND_ASSIGN(PagedArray); +}; +} // namespace +#endif // COURGETTE_BSDIFF_PAGED_ARRAY_H_ |