-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Syndica/19/prune_msgs
gossip: Prune Messages
- Loading branch information
Showing
23 changed files
with
827 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# parse arg of file name | ||
import sys | ||
import os | ||
|
||
if len(sys.argv) != 2: | ||
print("Usage: python remove_unused.py <dir name>") | ||
sys.exit() | ||
|
||
zig_files = [] | ||
dirs = [sys.argv[1]] | ||
while 1: | ||
d = dirs.pop() | ||
files = os.listdir(d) | ||
for file in files: | ||
full_path = os.path.join(d, file) | ||
if os.path.isdir(full_path): | ||
dirs.append(full_path) | ||
else: | ||
# if file ends in .zig | ||
if file.endswith('.zig'): | ||
zig_files.append(full_path) | ||
|
||
if len(dirs) == 0: | ||
break | ||
|
||
n_remove_iter = 0 | ||
n_removes = 1 | ||
while n_removes > 0: | ||
n_removes = 0 | ||
print(f"iteration: {n_remove_iter}, lines removed: {n_removes}") | ||
n_remove_iter += 1 | ||
|
||
for filename in zig_files: | ||
print(filename) | ||
|
||
# open and read lines of file | ||
with open(filename, 'r') as f: | ||
full_lines = f.readlines() | ||
|
||
# filter lines to start with 'const' or 'pub const' | ||
lines = [line for line in full_lines if line.startswith('const') or line.startswith('pub const')] | ||
|
||
# get lines which include '@import' | ||
lines = [line for line in lines if '@import' in line] | ||
|
||
# parse the value {VAR} name in 'const {VAR} = @import ...' | ||
import_var_names = [] | ||
for (i, line) in enumerate(full_lines): | ||
if not (line.startswith('const') or line.startswith('pub const')): | ||
continue | ||
|
||
if '@import' not in line: | ||
continue | ||
|
||
start_index = line.index("const ") | ||
end_index = line.index(" = ") | ||
var_name = line[start_index + 6:end_index] | ||
import_var_names.append((var_name, i)) | ||
|
||
unused_vars = import_var_names.copy() | ||
for i, line in enumerate(full_lines): | ||
|
||
for var, line_num in import_var_names: | ||
if (var in line) and (i != line_num): | ||
if (var, line_num) in unused_vars: | ||
unused_vars.remove((var, line_num)) | ||
|
||
new_lines = [] | ||
lines_to_remove = [i for (_, i) in unused_vars] | ||
n_removes += len(lines_to_remove) | ||
|
||
for (i, line) in enumerate(full_lines): | ||
if i in lines_to_remove: | ||
continue | ||
new_lines.append(line) | ||
|
||
print(unused_vars) | ||
|
||
# write | ||
with open(filename, 'w') as f: | ||
f.writelines(new_lines) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const std = @import("std"); | ||
|
||
/// ***ShredVersion*** | ||
/// Currently it's being manually set. | ||
/// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.