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

Side by Side Diff: net/disk_cache/simple/simple_util.cc

Issue 1977863003: SimpleCache: open with fewer seeks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@open-speeder-macbetter
Patch Set: actually fix test Created 4 years, 7 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 | « net/disk_cache/simple/simple_util.h ('k') | net/disk_cache/simple/simple_util_unittest.cc » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "net/disk_cache/simple/simple_util.h" 5 #include "net/disk_cache/simple/simple_util.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 std::string GetSparseFilenameFromEntryHash(uint64_t entry_hash) { 90 std::string GetSparseFilenameFromEntryHash(uint64_t entry_hash) {
91 return base::StringPrintf("%016" PRIx64 "_s", entry_hash); 91 return base::StringPrintf("%016" PRIx64 "_s", entry_hash);
92 } 92 }
93 93
94 std::string GetFilenameFromKeyAndFileIndex(const std::string& key, 94 std::string GetFilenameFromKeyAndFileIndex(const std::string& key,
95 int file_index) { 95 int file_index) {
96 return GetEntryHashKeyAsHexString(key) + 96 return GetEntryHashKeyAsHexString(key) +
97 base::StringPrintf("_%1d", file_index); 97 base::StringPrintf("_%1d", file_index);
98 } 98 }
99 99
100 int32_t GetDataSizeFromKeyAndFileSize(const std::string& key, 100 size_t GetHeaderSize(size_t key_length) {
101 int64_t file_size) { 101 return sizeof(SimpleFileHeader) + key_length;
102 }
103
104 int32_t GetDataSizeFromFileSize(size_t key_length, int64_t file_size) {
102 int64_t data_size = 105 int64_t data_size =
103 file_size - key.size() - sizeof(SimpleFileHeader) - sizeof(SimpleFileEOF); 106 file_size - key_length - sizeof(SimpleFileHeader) - sizeof(SimpleFileEOF);
104 return base::checked_cast<int32_t>(data_size); 107 return base::checked_cast<int32_t>(data_size);
105 } 108 }
106 109
107 int64_t GetFileSizeFromKeyAndDataSize(const std::string& key, 110 int64_t GetFileSizeFromDataSize(size_t key_length, int32_t data_size) {
108 int32_t data_size) { 111 return data_size + key_length + sizeof(SimpleFileHeader) +
109 return data_size + key.size() + sizeof(SimpleFileHeader) + 112 sizeof(SimpleFileEOF);
110 sizeof(SimpleFileEOF);
111 } 113 }
112 114
113 int GetFileIndexFromStreamIndex(int stream_index) { 115 int GetFileIndexFromStreamIndex(int stream_index) {
114 return (stream_index == 2) ? 1 : 0; 116 return (stream_index == 2) ? 1 : 0;
115 } 117 }
116 118
117 // TODO(clamy, gavinp): this should go in base 119 // TODO(clamy, gavinp): this should go in base
118 bool GetMTime(const base::FilePath& path, base::Time* out_mtime) { 120 bool GetMTime(const base::FilePath& path, base::Time* out_mtime) {
119 DCHECK(out_mtime); 121 DCHECK(out_mtime);
120 #if defined(OS_POSIX) 122 #if defined(OS_POSIX)
(...skipping 13 matching lines...) Expand all
134 base::File::Info file_info; 136 base::File::Info file_info;
135 if (!base::GetFileInfo(path, &file_info)) 137 if (!base::GetFileInfo(path, &file_info))
136 return false; 138 return false;
137 *out_mtime = file_info.last_modified; 139 *out_mtime = file_info.last_modified;
138 return true; 140 return true;
139 } 141 }
140 142
141 } // namespace simple_backend 143 } // namespace simple_backend
142 144
143 } // namespace disk_cache 145 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_util.h ('k') | net/disk_cache/simple/simple_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698