mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 13:04:15 -04:00
More cleanup
This commit is contained in:
parent
59d249c1fb
commit
df2ec0cafa
@ -386,6 +386,7 @@ class metadata_ final : public metadata_v2::impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: cleanup the walk logic
|
||||||
void walk_call(std::function<void(dir_entry_view)> const& func,
|
void walk_call(std::function<void(dir_entry_view)> const& func,
|
||||||
uint32_t self_index, uint32_t parent_index) const {
|
uint32_t self_index, uint32_t parent_index) const {
|
||||||
func(make_dir_entry_view(self_index, parent_index));
|
func(make_dir_entry_view(self_index, parent_index));
|
||||||
@ -757,6 +758,12 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
|
|||||||
std::function<void(dir_entry_view)> const& func) const {
|
std::function<void(dir_entry_view)> const& func) const {
|
||||||
std::vector<std::pair<uint32_t, uint32_t>> entries;
|
std::vector<std::pair<uint32_t, uint32_t>> entries;
|
||||||
|
|
||||||
|
if (auto dep = meta_.dir_entries()) {
|
||||||
|
entries.reserve(dep->size());
|
||||||
|
} else {
|
||||||
|
entries.reserve(meta_.inodes().size());
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto td = LOG_TIMED_DEBUG;
|
auto td = LOG_TIMED_DEBUG;
|
||||||
|
|
||||||
@ -765,7 +772,7 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (auto dep = meta_.dir_entries()) {
|
if (auto dep = meta_.dir_entries()) {
|
||||||
// first, partition files / non-files
|
// 1. partition non-files / files
|
||||||
auto mid =
|
auto mid =
|
||||||
std::stable_partition(entries.begin(), entries.end(),
|
std::stable_partition(entries.begin(), entries.end(),
|
||||||
[de = *dep, beg = file_inode_offset_,
|
[de = *dep, beg = file_inode_offset_,
|
||||||
@ -774,30 +781,45 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
|
|||||||
return ino < beg or ino >= end;
|
return ino < beg or ino >= end;
|
||||||
});
|
});
|
||||||
|
|
||||||
// now, order files by chunk block number
|
// 2. order files by chunk block number
|
||||||
|
// 2a. build mapping inode -> first chunk block
|
||||||
std::vector<uint32_t> first_chunk_block;
|
std::vector<uint32_t> first_chunk_block;
|
||||||
first_chunk_block.resize(dep->size());
|
|
||||||
auto chunk_table = meta_.chunk_table();
|
|
||||||
|
|
||||||
for (size_t ix = 0; ix < first_chunk_block.size(); ++ix) {
|
{
|
||||||
int ino = (*dep)[ix].inode_num();
|
auto td2 = LOG_TIMED_DEBUG;
|
||||||
if (ino >= file_inode_offset_ and ino < dev_inode_offset_) {
|
|
||||||
ino -= file_inode_offset_;
|
first_chunk_block.resize(dep->size());
|
||||||
if (ino >= unique_files_) {
|
auto chunk_table = meta_.chunk_table();
|
||||||
ino = shared_files_[ino - unique_files_] + unique_files_;
|
|
||||||
}
|
for (size_t ix = 0; ix < first_chunk_block.size(); ++ix) {
|
||||||
if (chunk_table[ino] != chunk_table[ino + 1]) {
|
int ino = (*dep)[ix].inode_num();
|
||||||
DWARFS_NOTHROW(first_chunk_block.at(ix)) =
|
if (ino >= file_inode_offset_ and ino < dev_inode_offset_) {
|
||||||
meta_.chunks()[chunk_table[ino]].block();
|
ino -= file_inode_offset_;
|
||||||
|
if (ino >= unique_files_) {
|
||||||
|
ino = shared_files_[ino - unique_files_] + unique_files_;
|
||||||
|
}
|
||||||
|
if (chunk_table[ino] != chunk_table[ino + 1]) {
|
||||||
|
first_chunk_block[ix] = meta_.chunks()[chunk_table[ino]].block();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td2 << "prepare first chunk block vector";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stable_sort(mid, entries.end(),
|
// 2b. sort second partition accordingly
|
||||||
[&first_chunk_block](auto const& a, auto const& b) {
|
{
|
||||||
return first_chunk_block[a.first] <
|
auto td2 = LOG_TIMED_DEBUG;
|
||||||
first_chunk_block[b.first];
|
|
||||||
});
|
std::stable_sort(mid, entries.end(),
|
||||||
|
[&first_chunk_block](auto const& a, auto const& b) {
|
||||||
|
return first_chunk_block[a.first] <
|
||||||
|
first_chunk_block[b.first];
|
||||||
|
});
|
||||||
|
|
||||||
|
td2 << "final sort of " << std::distance(mid, entries.end())
|
||||||
|
<< " file entries";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
std::sort(entries.begin(), entries.end(),
|
std::sort(entries.begin(), entries.end(),
|
||||||
[this](auto const& a, auto const& b) {
|
[this](auto const& a, auto const& b) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user