From 2a99a7e74a7f215066514fe81d2bfa6639d9eddd Mon Sep 17 00:00:00 2001 From: "Torne (Richard Coles)" Date: Thu, 28 Mar 2013 15:31:22 +0000 Subject: Merge from Chromium at DEPS revision r190564 This commit was generated by merge_to_master.py. Change-Id: Icadecbce29854b8fa25fd335b2c1949b5ca5d170 --- courgette/adjustment_method.cc | 2 +- courgette/base_test_unittest.cc | 2 +- courgette/base_test_unittest.h | 2 +- courgette/courgette.gyp | 4 +- courgette/courgette.h | 8 +- courgette/courgette_tool.cc | 60 ++++++------- courgette/ensemble_apply.cc | 18 ++-- courgette/memory_allocator.cc | 4 +- courgette/memory_allocator.h | 4 +- courgette/memory_monitor.cc | 10 +-- courgette/third_party/paged_array.h | 162 ++++++++++++++++++------------------ 11 files changed, 139 insertions(+), 137 deletions(-) (limited to 'courgette') diff --git a/courgette/adjustment_method.cc b/courgette/adjustment_method.cc index 53745d748b..ac0f0a1c2f 100644 --- a/courgette/adjustment_method.cc +++ b/courgette/adjustment_method.cc @@ -169,7 +169,7 @@ static std::string ToString(Node* node) { prefix.pop_back(); } - s += StringPrintf("%u", node->count_); + s += base::StringPrintf("%u", node->count_); s += " @"; s += base::Uint64ToString(node->edges_in_frequency_order.size()); s += "}"; diff --git a/courgette/base_test_unittest.cc b/courgette/base_test_unittest.cc index f85fd35e48..a0e7d05a95 100644 --- a/courgette/base_test_unittest.cc +++ b/courgette/base_test_unittest.cc @@ -17,7 +17,7 @@ void BaseTest::TearDown() { // Reads a test file into a string. std::string BaseTest::FileContents(const char* file_name) const { - FilePath file_path = test_dir_; + base::FilePath file_path = test_dir_; file_path = file_path.AppendASCII(file_name); std::string file_bytes; diff --git a/courgette/base_test_unittest.h b/courgette/base_test_unittest.h index a0733a4668..e4ea0ec0b3 100644 --- a/courgette/base_test_unittest.h +++ b/courgette/base_test_unittest.h @@ -23,7 +23,7 @@ class BaseTest : public testing::Test { virtual void SetUp(); virtual void TearDown(); - FilePath test_dir_; + base::FilePath test_dir_; }; #endif // COURGETTE_BASE_TEST_UNITTEST_H_ diff --git a/courgette/courgette.gyp b/courgette/courgette.gyp index 31276ae9f6..9cf075a19d 100644 --- a/courgette/courgette.gyp +++ b/courgette/courgette.gyp @@ -121,6 +121,8 @@ ], }], ], + # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + 'msvs_disabled_warnings': [4267, ], }, { 'target_name': 'courgette_fuzz', @@ -151,7 +153,7 @@ }, ], 'conditions': [ - ['OS=="win"', { + ['OS=="win" and target_arch=="ia32"', { 'targets': [ { 'target_name': 'courgette_lib64', diff --git a/courgette/courgette.h b/courgette/courgette.h index 2cd4cd7553..91b9038f40 100644 --- a/courgette/courgette.h +++ b/courgette/courgette.h @@ -7,7 +7,7 @@ #include // Required to define size_t on GCC -#include "base/file_path.h" +#include "base/files/file_path.h" namespace courgette { @@ -77,9 +77,9 @@ Status ApplyEnsemblePatch(SourceStream* old, SourceStream* patch, // Returns C_OK unless something went wrong. // This function first validates that the patch file has a proper header, so the // function can be used to 'try' a patch. -Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, - const FilePath::CharType* patch_file_name, - const FilePath::CharType* new_file_name); +Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, + const base::FilePath::CharType* patch_file_name, + const base::FilePath::CharType* new_file_name); // Generates a patch that will transform the bytes in |old| into the bytes in // |target|. diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc index 2714e0fe8f..4cc29f78ba 100644 --- a/courgette/courgette_tool.cc +++ b/courgette/courgette_tool.cc @@ -2,21 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include +#include #include "base/at_exit.h" #include "base/basictypes.h" #include "base/command_line.h" -#include "base/file_path.h" #include "base/file_util.h" +#include "base/files/file_path.h" #include "base/logging.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "courgette/third_party/bsdiff.h" #include "courgette/courgette.h" #include "courgette/streams.h" +#include "courgette/third_party/bsdiff.h" void PrintHelp() { @@ -47,7 +47,7 @@ void Problem(const char* format, ...) { exit(1); } -std::string ReadOrFail(const FilePath& file_name, const char* kind) { +std::string ReadOrFail(const base::FilePath& file_name, const char* kind) { int64 file_size = 0; if (!file_util::GetFileSize(file_name, &file_size)) Problem("Can't read %s file.", kind); @@ -59,7 +59,7 @@ std::string ReadOrFail(const FilePath& file_name, const char* kind) { } void WriteSinkToFile(const courgette::SinkStream *sink, - const FilePath& output_file) { + const base::FilePath& output_file) { int count = file_util::WriteFile(output_file, reinterpret_cast(sink->Buffer()), @@ -70,8 +70,8 @@ void WriteSinkToFile(const courgette::SinkStream *sink, Problem("Incomplete write."); } -void Disassemble(const FilePath& input_file, - const FilePath& output_file) { +void Disassemble(const base::FilePath& input_file, + const base::FilePath& output_file) { std::string buffer = ReadOrFail(input_file, "input"); courgette::AssemblyProgram* program = NULL; @@ -106,7 +106,7 @@ void Disassemble(const FilePath& input_file, WriteSinkToFile(&sink, output_file); } -bool Supported(const FilePath& input_file) { +bool Supported(const base::FilePath& input_file) { bool result = false; std::string buffer = ReadOrFail(input_file, "input"); @@ -141,9 +141,9 @@ bool Supported(const FilePath& input_file) { return result; } -void DisassembleAndAdjust(const FilePath& program_file, - const FilePath& model_file, - const FilePath& output_file) { +void DisassembleAndAdjust(const base::FilePath& program_file, + const base::FilePath& model_file, + const base::FilePath& output_file) { std::string program_buffer = ReadOrFail(program_file, "program"); std::string model_buffer = ReadOrFail(model_file, "reference"); @@ -196,9 +196,9 @@ void DisassembleAndAdjust(const FilePath& program_file, // original file's stream and the new file's stream. This is completely // uninteresting to users, but it is handy for seeing how much each which // streams are contributing to the final file size. Adjustment is optional. -void DisassembleAdjustDiff(const FilePath& model_file, - const FilePath& program_file, - const FilePath& output_file_root, +void DisassembleAdjustDiff(const base::FilePath& model_file, + const base::FilePath& program_file, + const base::FilePath& output_file_root, bool adjust) { std::string model_buffer = ReadOrFail(model_file, "'old'"); std::string program_buffer = ReadOrFail(program_file, "'new'"); @@ -275,8 +275,8 @@ void DisassembleAdjustDiff(const FilePath& model_file, } } -void Assemble(const FilePath& input_file, - const FilePath& output_file) { +void Assemble(const base::FilePath& input_file, + const base::FilePath& output_file) { std::string buffer = ReadOrFail(input_file, "input"); courgette::SourceStreamSet sources; @@ -297,9 +297,9 @@ void Assemble(const FilePath& input_file, WriteSinkToFile(&sink, output_file); } -void GenerateEnsemblePatch(const FilePath& old_file, - const FilePath& new_file, - const FilePath& patch_file) { +void GenerateEnsemblePatch(const base::FilePath& old_file, + const base::FilePath& new_file, + const base::FilePath& patch_file) { std::string old_buffer = ReadOrFail(old_file, "'old' input"); std::string new_buffer = ReadOrFail(new_file, "'new' input"); @@ -317,9 +317,9 @@ void GenerateEnsemblePatch(const FilePath& old_file, WriteSinkToFile(&patch_stream, patch_file); } -void ApplyEnsemblePatch(const FilePath& old_file, - const FilePath& patch_file, - const FilePath& new_file) { +void ApplyEnsemblePatch(const base::FilePath& old_file, + const base::FilePath& patch_file, + const base::FilePath& new_file) { // We do things a little differently here in order to call the same Courgette // entry point as the installer. That entry point point takes file names and // returns an status code but does not output any diagnostics. @@ -374,9 +374,9 @@ void ApplyEnsemblePatch(const FilePath& old_file, Problem("-apply failed."); } -void GenerateBSDiffPatch(const FilePath& old_file, - const FilePath& new_file, - const FilePath& patch_file) { +void GenerateBSDiffPatch(const base::FilePath& old_file, + const base::FilePath& new_file, + const base::FilePath& patch_file) { std::string old_buffer = ReadOrFail(old_file, "'old' input"); std::string new_buffer = ReadOrFail(new_file, "'new' input"); @@ -394,9 +394,9 @@ void GenerateBSDiffPatch(const FilePath& old_file, WriteSinkToFile(&patch_stream, patch_file); } -void ApplyBSDiffPatch(const FilePath& old_file, - const FilePath& patch_file, - const FilePath& new_file) { +void ApplyBSDiffPatch(const base::FilePath& old_file, + const base::FilePath& patch_file, + const base::FilePath& new_file) { std::string old_buffer = ReadOrFail(old_file, "'old' input"); std::string patch_buffer = ReadOrFail(patch_file, "'patch' input"); @@ -438,10 +438,10 @@ int main(int argc, const char* argv[]) { bool cmd_spread_1_adjusted = command_line.HasSwitch("gen1a"); bool cmd_spread_1_unadjusted = command_line.HasSwitch("gen1u"); - std::vector values; + std::vector values; const CommandLine::StringVector& args = command_line.GetArgs(); for (size_t i = 0; i < args.size(); ++i) { - values.push_back(FilePath(args[i])); + values.push_back(base::FilePath(args[i])); } // '-repeat=N' is for debugging. Running many iterations can reveal leaks and diff --git a/courgette/ensemble_apply.cc b/courgette/ensemble_apply.cc index 475cdf2672..61a3602a64 100644 --- a/courgette/ensemble_apply.cc +++ b/courgette/ensemble_apply.cc @@ -8,8 +8,8 @@ #include "base/basictypes.h" #include "base/file_util.h" +#include "base/files/memory_mapped_file.h" #include "base/logging.h" - #include "courgette/crc.h" #include "courgette/region.h" #include "courgette/streams.h" @@ -372,13 +372,13 @@ Status ApplyEnsemblePatch(SourceStream* base, return C_OK; } -Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, - const FilePath::CharType* patch_file_name, - const FilePath::CharType* new_file_name) { +Status ApplyEnsemblePatch(const base::FilePath::CharType* old_file_name, + const base::FilePath::CharType* patch_file_name, + const base::FilePath::CharType* new_file_name) { // First read enough of the patch file to validate the header is well-formed. // A few varint32 numbers should fit in 100. - FilePath patch_file_path(patch_file_name); - file_util::MemoryMappedFile patch_file; + base::FilePath patch_file_path(patch_file_name); + base::MemoryMappedFile patch_file; if (!patch_file.Initialize(patch_file_path)) return C_READ_OPEN_ERROR; @@ -391,8 +391,8 @@ Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, return status; // Read the old_file. - FilePath old_file_path(old_file_name); - file_util::MemoryMappedFile old_file; + base::FilePath old_file_path(old_file_name); + base::MemoryMappedFile old_file; if (!old_file.Initialize(old_file_path)) return C_READ_ERROR; @@ -408,7 +408,7 @@ Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, return status; // Write the patched data to |new_file_name|. - FilePath new_file_path(new_file_name); + base::FilePath new_file_path(new_file_name); int written = file_util::WriteFile( new_file_path, diff --git a/courgette/memory_allocator.cc b/courgette/memory_allocator.cc index b3a45b4b7f..c2bbd64b75 100644 --- a/courgette/memory_allocator.cc +++ b/courgette/memory_allocator.cc @@ -9,7 +9,7 @@ #include "base/file_util.h" #include "base/stringprintf.h" -#ifdef OS_WIN +#if defined(OS_WIN) namespace courgette { @@ -31,7 +31,7 @@ void TempFile::Close() { bool TempFile::Create() { DCHECK(file_ == base::kInvalidPlatformFileValue); - FilePath path; + base::FilePath path; if (!file_util::CreateTemporaryFile(&path)) return false; diff --git a/courgette/memory_allocator.h b/courgette/memory_allocator.h index 08defe46e7..d848915b5f 100644 --- a/courgette/memory_allocator.h +++ b/courgette/memory_allocator.h @@ -8,7 +8,7 @@ #include #include "base/basictypes.h" -#include "base/file_path.h" +#include "base/files/file_path.h" #include "base/logging.h" #include "base/platform_file.h" @@ -55,7 +55,7 @@ typedef bool CheckBool; namespace courgette { -#ifdef OS_WIN +#if defined(OS_WIN) // Manages a temporary file. The file is created in the %TEMP% folder and // is deleted when the file handle is closed. diff --git a/courgette/memory_monitor.cc b/courgette/memory_monitor.cc index dba8a88cb1..89f82fb9b0 100644 --- a/courgette/memory_monitor.cc +++ b/courgette/memory_monitor.cc @@ -16,17 +16,17 @@ struct H { int i = 0; for (M::iterator p = m_.begin(); p != m_.end(); ++p, ++i) { size_t s = p->first; - LOG(INFO) << StringPrintf("%3d %8u: %8u %8u %8u %8u", i, s, + LOG(INFO) << base::StringPrintf("%3d %8u: %8u %8u %8u %8u", i, s, m_[s], c_[s], h_[s], h_[s] * s); } LOG(INFO) << "Peak " << fmt(high_); } std::string fmt(size_t s) { - if (s > 1000000000) return StringPrintf("%.3gG", s/(1000000000.0)); - if (s > 1000000) return StringPrintf("%.3gM", s/(1000000.)); - if (s > 9999) return StringPrintf("%.3gk", s/(1000.)); - return StringPrintf("%d", (int)s); + if (s > 1000000000) return base::StringPrintf("%.3gG", s/(1000000000.0)); + if (s > 1000000) return base::StringPrintf("%.3gM", s/(1000000.)); + if (s > 9999) return base::StringPrintf("%.3gk", s/(1000.)); + return base::StringPrintf("%d", (int)s); } void tick(size_t w, char sign) { diff --git a/courgette/third_party/paged_array.h b/courgette/third_party/paged_array.h index e9d0299031..b12b695817 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 - -#include "base/basictypes.h" - -namespace courgette { - -// PagedArray implements an array stored using many fixed-size pages. -template -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 + +#include "base/basictypes.h" + +namespace courgette { + +// PagedArray implements an array stored using many fixed-size pages. +template +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_ -- cgit v1.2.3