Rename Array to Vector

Finally get rid of the C style vector, rename the template class to its proper name
This commit is contained in:
topjohnwu
2018-11-08 05:03:59 -05:00
parent b6965105b7
commit 8745c7884e
15 changed files with 52 additions and 56 deletions

View File

@@ -56,7 +56,7 @@ cpio_entry::~cpio_entry() {
// Define the way to sort cpio_entry
template<>
int(*Array<cpio_entry*>::_cmp)(cpio_entry*&, cpio_entry*&) = [](auto a, auto b) -> int {
int(*Vector<cpio_entry*>::_cmp)(cpio_entry*&, cpio_entry*&) = [](auto a, auto b) -> int {
if (a == b) return 0;
if (a == nullptr) return 1;
if (b == nullptr) return -1;
@@ -148,7 +148,7 @@ void cpio::insert(cpio_entry *e) {
}
}
void cpio::insert(Array<cpio_entry *> &arr) {
void cpio::insert(Vector<cpio_entry *> &arr) {
for (auto &e : arr)
insert(e);
}

View File

@@ -3,7 +3,7 @@
#include <stdint.h>
#include "array.h"
#include "Vector.h"
#include "CharArray.h"
struct cpio_newc_header {
@@ -57,14 +57,14 @@ public:
void makedir(mode_t mode, const char *name);
void ln(const char *target, const char *name);
void add(mode_t mode, const char *name, const char *file);
void insert(Array<cpio_entry *> &arr);
void insert(Vector<cpio_entry *> &arr);
bool mv(const char *from, const char *to);
void extract();
bool extract(const char *name, const char *file);
void sort();
protected:
Array<cpio_entry *> arr;
Vector<cpio_entry *> arr;
};
#endif

View File

@@ -3,7 +3,6 @@
#include <sys/stat.h>
#include "magiskboot.h"
#include "array.h"
#include "cpio.h"
#include "utils.h"
@@ -14,7 +13,7 @@ public:
int test();
char * sha1();
void restore();
void backup(Array<cpio_entry*> &bak, const char *orig, const char *sha1);
void backup(Vector<cpio_entry*> &bak, const char *orig, const char *sha1);
};
void magisk_cpio::patch(bool keepverity, bool keepforceencrypt) {
@@ -110,7 +109,7 @@ void magisk_cpio::restore() {
rm("magisk", true);
}
void magisk_cpio::backup(Array<cpio_entry*> &bak, const char *orig, const char *sha1) {
void magisk_cpio::backup(Vector<cpio_entry*> &bak, const char *orig, const char *sha1) {
cpio_entry *m, *n, *rem, *cksm;
char buf[PATH_MAX];
@@ -230,13 +229,13 @@ int cpio_commands(int argc, char *argv[]) {
free(sha1);
return 0;
} else if (cmdc >= 2 && strcmp(cmdv[0], "backup") == 0) {
Array<cpio_entry*> bak;
Vector<cpio_entry*> bak;
cpio.backup(bak, cmdv[1], cmdv[2]);
cpio.insert(bak);
} else if (cmdc >= 4 && strcmp(cmdv[0], "magisk") == 0) {
cpio.patch(strcmp(cmdv[2], "true") == 0, strcmp(cmdv[3], "true") == 0);
Array<cpio_entry*> bak;
Vector<cpio_entry*> bak;
cpio.backup(bak, cmdv[1], cmdv[4]);
auto e = new cpio_entry();