[thin_ls] only run pass1 if needed

This commit is contained in:
Joe Thornber 2016-01-19 15:50:15 +00:00
parent f3e23c5417
commit 5aaa26fe34

View File

@ -341,6 +341,21 @@ namespace {
//------------------------------------------------ //------------------------------------------------
bool pass1_needed(vector<output_field> const &fields) {
vector<output_field>::const_iterator it;
for (it = fields.begin(); it != fields.end(); ++it) {
if (*it == EXCLUSIVE_BLOCKS ||
*it == SHARED_BLOCKS ||
*it == EXCLUSIVE_SECTORS ||
*it == SHARED_SECTORS ||
*it == EXCLUSIVE ||
*it == SHARED)
return true;
}
return false;
}
void ls_(string const &path, ostream &out, struct flags &flags) { void ls_(string const &path, ostream &out, struct flags &flags) {
grid_layout grid; grid_layout grid;
@ -359,11 +374,14 @@ namespace {
walk_device_tree(*md->details_, de, *dd_policy); walk_device_tree(*md->details_, de, *dd_policy);
mapping_set mappings(md->data_sm_->get_nr_blocks()); mapping_set mappings(md->data_sm_->get_nr_blocks());
dd_map const &map = de.get_details();
dd_map::const_iterator it; dd_map::const_iterator it;
for (it = map.begin(); it != map.end(); ++it) dd_map const &map = de.get_details();
pass1(md, mappings, it->first);
bool some_exclusive_fields = pass1_needed(flags.fields);
if (some_exclusive_fields) {
for (it = map.begin(); it != map.end(); ++it)
pass1(md, mappings, it->first);
}
if (flags.headers) if (flags.headers)
print_headers(grid, flags.fields); print_headers(grid, flags.fields);
@ -371,7 +389,10 @@ namespace {
for (it = map.begin(); it != map.end(); ++it) { for (it = map.begin(); it != map.end(); ++it) {
vector<output_field>::const_iterator f; vector<output_field>::const_iterator f;
optional<block_address> exclusive; block_address exclusive = 0;
if (some_exclusive_fields)
exclusive = count_exclusives(md, mappings, it->first);
for (f = flags.fields.begin(); f != flags.fields.end(); ++f) { for (f = flags.fields.begin(); f != flags.fields.end(); ++f) {
switch (*f) { switch (*f) {
@ -384,15 +405,11 @@ namespace {
break; break;
case EXCLUSIVE_BLOCKS: case EXCLUSIVE_BLOCKS:
if (!exclusive) grid.field(exclusive);
exclusive = count_exclusives(md, mappings, it->first);
grid.field(*exclusive);
break; break;
case SHARED_BLOCKS: case SHARED_BLOCKS:
if (!exclusive) grid.field(it->second.mapped_blocks_ - exclusive);
exclusive = count_exclusives(md, mappings, it->first);
grid.field(it->second.mapped_blocks_ - *exclusive);
break; break;
case MAPPED_SECTORS: case MAPPED_SECTORS:
@ -400,15 +417,11 @@ namespace {
break; break;
case EXCLUSIVE_SECTORS: case EXCLUSIVE_SECTORS:
if (!exclusive) grid.field(exclusive * block_size);
exclusive = count_exclusives(md, mappings, it->first);
grid.field(*exclusive * block_size);
break; break;
case SHARED_SECTORS: case SHARED_SECTORS:
if (!exclusive) grid.field((it->second.mapped_blocks_ - exclusive) * block_size);
exclusive = count_exclusives(md, mappings, it->first);
grid.field((it->second.mapped_blocks_ - *exclusive) * block_size);
break; break;
@ -419,20 +432,14 @@ namespace {
break; break;
case EXCLUSIVE: case EXCLUSIVE:
if (!exclusive)
exclusive = count_exclusives(md, mappings, it->first);
grid.field( grid.field(
format_disk_unit(*exclusive * block_size, format_disk_unit(exclusive * block_size,
UNIT_SECTOR)); UNIT_SECTOR));
break; break;
case SHARED: case SHARED:
if (!exclusive)
exclusive = count_exclusives(md, mappings, it->first);
grid.field( grid.field(
format_disk_unit((it->second.mapped_blocks_ - *exclusive) * format_disk_unit((it->second.mapped_blocks_ - exclusive) *
block_size, UNIT_SECTOR)); block_size, UNIT_SECTOR));
break; break;