Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1050)

Side by Side Diff: courgette/courgette_tool.cc

Issue 2143973004: Use memory mapped file in courgette_tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make BufferedFileReader const correct Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 vfprintf(stderr, format, args); 50 vfprintf(stderr, format, args);
51 fprintf(stderr, "\n"); 51 fprintf(stderr, "\n");
52 va_end(args); 52 va_end(args);
53 exit(1); 53 exit(1);
54 } 54 }
55 55
56 // A file reader that calls Problem() on failure. 56 // A file reader that calls Problem() on failure.
57 class BufferedFileReader { 57 class BufferedFileReader {
58 public: 58 public:
59 BufferedFileReader(const base::FilePath& file_name, const char* kind) { 59 BufferedFileReader(const base::FilePath& file_name, const char* kind) {
60 int64_t file_size = 0; 60 if (!buffer_.Initialize(file_name)) {
61 if (!base::GetFileSize(file_name, &file_size))
62 Problem("Can't read %s file.", kind); 61 Problem("Can't read %s file.", kind);
63 buffer_.reserve(static_cast<size_t>(file_size)); 62 }
huangs 2016/07/14 21:25:55 Can skip {}.
etiennep 2016/07/14 21:32:17 Done.
64 if (!base::ReadFileToString(file_name, &buffer_))
65 Problem("Can't read %s file.", kind);
66 } 63 }
67 const uint8_t* data() { 64 const uint8_t* data() const {
huangs 2016/07/14 21:25:55 Move into 1 line like length()? Or make length() m
etiennep 2016/07/14 21:32:17 Done.
68 return reinterpret_cast<const uint8_t*>(buffer_.data()); 65 return buffer_.data();
69 } 66 }
70 size_t length() { return buffer_.length(); } 67 size_t length() const { return buffer_.length(); }
71 68
72 private: 69 private:
73 std::string buffer_; 70 base::MemoryMappedFile buffer_;
74 }; 71 };
75 72
76 void WriteSinkToFile(const courgette::SinkStream *sink, 73 void WriteSinkToFile(const courgette::SinkStream *sink,
77 const base::FilePath& output_file) { 74 const base::FilePath& output_file) {
78 int count = 75 int count =
79 base::WriteFile(output_file, 76 base::WriteFile(output_file,
80 reinterpret_cast<const char*>(sink->Buffer()), 77 reinterpret_cast<const char*>(sink->Buffer()),
81 static_cast<int>(sink->Length())); 78 static_cast<int>(sink->Length()));
82 if (count == -1) 79 if (count == -1)
83 Problem("Can't write output."); 80 Problem("Can't write output.");
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); 513 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>");
517 DisassembleAdjustDiff(values[0], values[1], values[2], 514 DisassembleAdjustDiff(values[0], values[1], values[2],
518 cmd_spread_1_adjusted); 515 cmd_spread_1_adjusted);
519 } else { 516 } else {
520 UsageProblem("No operation specified"); 517 UsageProblem("No operation specified");
521 } 518 }
522 } 519 }
523 520
524 return 0; 521 return 0;
525 } 522 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698