Skip to content

Commit 0ed9ebb

Browse files
Chore/remove boost (#52)
* Remove boost filesystem * Remove boost format * Update gitignore * Remove algorithm * Last touches
1 parent 1cc4382 commit 0ed9ebb

File tree

14 files changed

+75
-63
lines changed

14 files changed

+75
-63
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ DartConfiguration.tcl
4343

4444
# Clangd Cache
4545
.cache/
46+
47+
# Ninja logs
48+
trace*.json
49+
ninja_log

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(Boost_CMAKE_CXX_STANDARD 17)
1919
set(CMAKE_CXX_STANDARD 17)
2020
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2121

22-
set(BOOST_INCLUDE_LIBRARIES filesystem system iostreams uuid format algorithm)
22+
set(BOOST_INCLUDE_LIBRARIES iostreams uuid algorithm)
2323

2424
include(FetchContent)
2525
FetchContent_Declare(

doc/case studies/Optimising binary size.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,33 @@ Could this take up majority of the binary as well? Looks like most of the symbol
3838
0000000100094020 0000000000000000 D __ZGVZNK5TCLAP12ArgException4whatEvE2ex
3939
0000000100094008 0000000000000000 D __ZZNK5TCLAP12ArgException4whatEvE2ex
4040
0000000100094000 0000000000000000 D __ZZN5TCLAP3Arg12delimiterRefEvE5delim
41-
```
41+
```
42+
43+
# After removing filesystem
44+
45+
`du -sh app/gyt`: 396K
46+
47+
```
48+
0000000100078041 0000000000000000 b __ZN5boost11optional_nsL16in_place_init_ifE
49+
0000000100078040 0000000000000000 b __ZN5boost11optional_nsL13in_place_initE
50+
0000000100078038 0000000000000000 D __ZZNK5boost17integral_constantIbLb1EEcvRKN4mpl_5bool_ILb1EEEEvE5pdata
51+
0000000100078030 0000000000000000 D __ZZN5TCLAP24OptionalUnlabeledTracker18alreadyOptionalRefEvE2ct
52+
0000000100078028 0000000000000000 D __ZZN5TCLAP3Arg13ignoreRestRefEvE3ign
53+
0000000100078020 0000000000000000 D __ZGVZNK5TCLAP12ArgException4whatEvE2ex
54+
0000000100078008 0000000000000000 D __ZZNK5TCLAP12ArgException4whatEvE2ex
55+
0000000100078000 0000000000000000 D __ZZN5TCLAP3Arg12delimiterRefEvE5delim
56+
0000000100074980 0000000000000000 s __ZTVN5boost9iostreams13stream_bufferINS0_6detail12mode_adapterINS0_6outputENSt3__114basic_iostreamIcNS5_11char_traitsIcEEEEEES8_NS5_9allocatorIcEES4_EE
57+
0000000100074968 0000000000000000 s __ZTIN5boost9iostreams21basic_zlib_compressorINSt3__19allocatorIcEEEE
58+
0000000100074958 0000000000000000 s __ZTIN5boost9iostreams16symmetric_filterINS0_6detail20zlib_compressor_implINSt3__19allocatorIcEEEES6_EE
59+
0000000100074900 0000000000000000 s __ZTIN5boost9iostreams16symmetric_filterINS0_6detail20zlib_compressor_implINSt3__19allocatorIcEEEES6_E8categoryE
60+
0000000100074888 0000000000000000 s __ZTCN5boost9iostreams16symmetric_filterINS0_6detail20zlib_compressor_implINSt3__19allocatorIcEEEES6_E8categoryE8_NS0_10filter_tagE
61+
0000000100074848 0000000000000000 s __ZTCN5boost9iostreams16symmetric_filterINS0_6detail20zlib_compressor_implINSt3__19allocatorIcEEEES6_E8categoryE0_NS0_8dual_useE
62+
0000000100074750 0000000000000000 s __ZTVN5boost9iostreams16symmetric_filterINS0_6detail20zlib_compressor_implINSt3__19allocatorIcEEEES6_E8categoryE
63+
0000000100074688 0000000000000000 s __ZTVN5boost9iostreams6detail18indirect_streambufINS0_21basic_zlib_compressorINSt3__19allocatorIcEEEENS4_11char_traitsIcEES6_NS0_6outputEEE
64+
0000000100074670 0000000000000000 s __ZTIN5boost9iostreams13stream_bufferINS0_21basic_zlib_compressorINSt3__19allocatorIcEEEENS3_11char_traitsIcEES5_NS0_6outputEEE
65+
0000000100074658 0000000000000000 s __ZTIN5boost9iostreams6detail18indirect_streambufINS0_21basic_zlib_compressorINSt3__19allocatorIcEEEENS4_11char_traitsIcEES6_NS0_6outputEEE
66+
0000000100074590 0000000000000000 s __ZTVN5boost9iostreams13stream_bufferINS0_21basic_zlib_compressorINSt3__19allocatorIcEEEENS3_11char_traitsIcEES5_NS0_6outputEEE
67+
0000000100074578 0000000000000000 s __ZTIN5boost6detail17sp_counted_impl_pINS_9iostreams16symmetric_filterINS2_6detail20zlib_compressor_implINSt3__19allocatorIcEEEES8_E4implEEE
68+
```
69+
70+
Removing format: 364K

include/blob.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef BLOB_H
22
#define BLOB_H
33

4-
#include <boost/filesystem.hpp>
54
#include <string>
65

76
#include "object.h"

include/object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef OBJECT_H
22
#define OBJECT_H
33

4-
#include <boost/filesystem.hpp>
4+
#include <filesystem>
55
#include <string>
66

77
#include "repository.h"
88

9-
namespace fs = boost::filesystem;
9+
namespace fs = std::filesystem;
1010
class GitObject {
1111
public:
1212
GitObject();

include/repository.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#ifndef REPOSITORY_H
22
#define REPOSITORY_H
33

4-
#include <boost/filesystem.hpp>
4+
#include <filesystem>
55
#include <optional>
66
#include <string>
77

8-
namespace fs = boost::filesystem;
8+
namespace fs = std::filesystem;
99
class GitRepository {
1010
public:
1111
GitRepository(fs::path worktree, fs::path gitdir);

include/tree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#define TREE_H
33

44
#include "object.h"
5-
#include <boost/filesystem.hpp>
5+
#include <filesystem>
66
#include <string>
77
#include <unordered_map>
88

9-
namespace fs = boost::filesystem;
9+
namespace fs = std::filesystem;
1010
class GitTree : public GitObject {
1111
public:
1212
GitTree(const std::string &data = std::string(""));

include/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef UTIL_H
22
#define UTIL_H
33

4-
#include <boost/filesystem.hpp>
4+
#include <filesystem>
55
#include <string>
6-
namespace fs = boost::filesystem;
6+
namespace fs = std::filesystem;
77

88
std::string read_file(const fs::path &filePath, bool remove_newline = false);
99
bool create_file(const fs::path &filePath, const std::string &content = "");

src/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
add_library(boost_libraries INTERFACE)
33
target_link_libraries(
44
boost_libraries
5-
INTERFACE Boost::filesystem
6-
Boost::system
7-
Boost::iostreams
5+
INTERFACE Boost::iostreams
86
Boost::uuid
9-
Boost::format
107
Boost::algorithm)
118

129
add_library(util util.cpp)

src/blob.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#include "blob.h"
22

3-
#include <boost/algorithm/string.hpp>
4-
#include <boost/format.hpp>
5-
#include <boost/iostreams/copy.hpp>
6-
#include <boost/iostreams/filter/zlib.hpp>
7-
#include <boost/iostreams/filtering_streambuf.hpp>
83
#include <string>
94

105
#include "repository.h"

src/object.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
#include "commit.h"
44
#include "tree.h"
55
#include "util.h"
6-
#include <boost/algorithm/string.hpp>
7-
#include <boost/format.hpp>
86
#include <boost/iostreams/copy.hpp>
9-
#include <boost/iostreams/detail/optional.hpp>
107
#include <boost/iostreams/filter/zlib.hpp>
118
#include <boost/iostreams/filtering_streambuf.hpp>
129

1310
#include <fstream>
1411
#include <iostream>
1512
#include <sstream>
1613
#include <stdexcept>
17-
#include <vector>
1814

1915
GitObject::GitObject() { this->init(); }
2016
GitObject::GitObject(const std::string &format) { this->format = format; }
@@ -24,9 +20,8 @@ void GitObject::init() {}
2420
GitObject *GitObject::read(GitRepository &repo, const std::string &sha) {
2521
std::string dir = sha.substr(0, 2);
2622
std::string path = sha.substr(2);
27-
std::string file_path = (boost::format("objects/%1%/%2%") % dir % path).str();
28-
fs::path file_to_create = fs::path(file_path);
29-
fs::path paths = repo.file(file_to_create);
23+
fs::path file_path = fs::path("objects") / dir / path;
24+
fs::path paths = repo.file(file_path);
3025

3126
if (!fs::is_regular_file(paths)) {
3227
throw std::runtime_error(paths.string() + " is not found");
@@ -77,11 +72,9 @@ std::string GitObject::write(GitRepository &repo, std::string &type,
7772
std::string sha = sha1_hexdigest(result);
7873

7974
if (write) {
80-
std::string file_path =
81-
(boost::format("objects/%1%/%2%") % sha.substr(0, 2) % sha.substr(2))
82-
.str();
83-
fs::path file_to_create = fs::path(file_path);
84-
fs::path paths = repo.file(file_to_create);
75+
fs::path file_path =
76+
fs::path("objects") / sha.substr(0, 2) / sha.substr(2);
77+
fs::path paths = repo.file(file_path);
8578

8679
// compress files
8780
std::stringstream compressed;

src/repository.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "repository.h"
2-
#include "boost/filesystem/path.hpp"
32
#include "inih/INIReader.h"
43
#include "util.h"
4+
#include <filesystem>
55
#include <iostream>
66

7-
namespace fs = boost::filesystem;
7+
namespace fs = std::filesystem;
88

99
GitRepository::GitRepository(std::string path, bool force)
1010
: worktree(fs::path(path)), gitdir(fs::path(path) / ".git") {
@@ -83,7 +83,7 @@ fs::path GitRepository::dir(const fs::path &path, bool mkdir) {
8383
Returns and optionally creates a path to a file or a directory
8484
*/
8585
fs::path GitRepository::file(fs::path &path, bool mkdir) {
86-
if (dir(path.branch_path(), mkdir) != fs::path("")) {
86+
if (dir(path.parent_path(), mkdir) != fs::path("")) {
8787
return repo_path(path);
8888
}
8989
return fs::path("");

src/tree.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "object.h"
44
#include "repository.h"
55
#include "util.h"
6-
#include <boost/filesystem.hpp>
76
#include <iomanip>
87
#include <iostream>
98
#include <sstream>
@@ -99,8 +98,7 @@ void GitTree::instantiate_tree(GitTree *treeToInstantiate, GitTree *curr_tree,
9998
}
10099
// assumption here: the file is created, so change the file mode
101100
if (mode != curr_mode) {
102-
boost::filesystem::permissions(new_file_path,
103-
get_unix_permissions(mode));
101+
fs::permissions(new_file_path, get_unix_permissions(mode));
104102
}
105103
} else {
106104
// not found in the current tree, create it
@@ -113,7 +111,7 @@ void GitTree::instantiate_tree(GitTree *treeToInstantiate, GitTree *curr_tree,
113111
instantiate_tree(subTreeToInstantiate, new_file_path);
114112
}
115113
// assumption here: the file is created, so change the file mode
116-
boost::filesystem::permissions(new_file_path, get_unix_permissions(mode));
114+
fs::permissions(new_file_path, get_unix_permissions(mode));
117115
}
118116
}
119117
// remove items that are not in the tree that I am instantiating
@@ -151,6 +149,6 @@ void GitTree::instantiate_tree(GitTree *treeToInstantiate,
151149
instantiate_tree(subTreeToInstantiate, new_file_path);
152150
}
153151

154-
boost::filesystem::permissions(new_file_path, get_unix_permissions(mode));
152+
fs::permissions(new_file_path, get_unix_permissions(mode));
155153
}
156154
}

src/util.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <boost/algorithm/string.hpp>
2-
#include <boost/filesystem.hpp>
32
#include <boost/uuid/detail/sha1.hpp>
3+
#include <filesystem>
44
#include <fstream>
55
#include <iomanip>
66
#include <iostream>
77
#include <sstream>
88
#include <string>
99

10-
namespace fs = boost::filesystem;
10+
namespace fs = std::filesystem;
1111

1212
std::string read_file(const fs::path &filePath, bool remove_newline = false) {
1313
try {
@@ -52,10 +52,10 @@ bool create_file(const fs::path &filePath, const std::string &content = "") {
5252
} else {
5353
std::cerr << "Error opening the file for writing: " << filePath << "\n"
5454
<< "Parent path exists: " << fs::exists(filePath.parent_path())
55-
<< "\n"
56-
<< "Permissions: "
57-
<< fs::status(filePath.parent_path()).permissions()
58-
<< std::endl;
55+
<< "\n";
56+
// << "Permissions: "
57+
// << fs::status(filePath.parent_path()).permissions()
58+
// << std::endl;
5959
return false;
6060
}
6161
} catch (const std::exception &e) {
@@ -113,40 +113,37 @@ fs::perms get_unix_permissions(int mode) {
113113
std::string file_type = get_file_type(mode);
114114
// set default permission for directories
115115
if (file_type == "tree") {
116-
return boost::filesystem::perms::owner_read |
117-
boost::filesystem::perms::owner_write |
118-
boost::filesystem::perms::owner_exe |
119-
boost::filesystem::perms::group_read |
120-
boost::filesystem::perms::group_exe |
121-
boost::filesystem::perms::others_read |
122-
boost::filesystem::perms::others_exe;
116+
return fs::perms::owner_read | fs::perms::owner_write |
117+
fs::perms::owner_exec | fs::perms::group_read |
118+
fs::perms::group_exec | fs::perms::others_read |
119+
fs::perms::others_exec;
123120
}
124121
mode = mode & 0x1FF;
125-
boost::filesystem::perms permissions = fs::perms::no_perms;
122+
fs::perms permissions = fs::perms::none;
126123

127124
// Owner permissions
128125
if (mode & 0400)
129-
permissions |= boost::filesystem::perms::owner_read;
126+
permissions |= fs::perms::owner_read;
130127
if (mode & 0200)
131-
permissions |= boost::filesystem::perms::owner_write;
128+
permissions |= fs::perms::owner_write;
132129
if (mode & 0100)
133-
permissions |= boost::filesystem::perms::owner_exe;
130+
permissions |= fs::perms::owner_exec;
134131

135132
// Group permissions
136133
if (mode & 0040)
137-
permissions |= boost::filesystem::perms::group_read;
134+
permissions |= fs::perms::group_read;
138135
if (mode & 0020)
139-
permissions |= boost::filesystem::perms::group_write;
136+
permissions |= fs::perms::group_write;
140137
if (mode & 0010)
141-
permissions |= boost::filesystem::perms::group_exe;
138+
permissions |= fs::perms::group_exec;
142139

143140
// Others permissions
144141
if (mode & 0004)
145-
permissions |= boost::filesystem::perms::others_read;
142+
permissions |= fs::perms::others_read;
146143
if (mode & 0002)
147-
permissions |= boost::filesystem::perms::others_write;
144+
permissions |= fs::perms::others_write;
148145
if (mode & 0001)
149-
permissions |= boost::filesystem::perms::others_exe;
146+
permissions |= fs::perms::others_exec;
150147

151148
return permissions;
152149
}

0 commit comments

Comments
 (0)