NetBpfLoad: less copies
This is a cherry-pick of ag/34620709 to NetBpfLoad Test: TH Flag: EXEMPT no-op Bug: 428792764 Change-Id: Ia5aaa30cab71a2051b6c787824798958f2dee3f5
This commit is contained in:
parent
e9dcc62d2d
commit
1ae10a006e
1 changed files with 4 additions and 10 deletions
|
|
@ -349,15 +349,12 @@ static int readSectionByName(const char* name, ifstream& elfFile, vector<char>&
|
|||
if (!secname) continue;
|
||||
|
||||
if (!strcmp(secname, name)) {
|
||||
vector<char> dataTmp;
|
||||
dataTmp.resize(shTable[i].sh_size);
|
||||
|
||||
elfFile.seekg(shTable[i].sh_offset);
|
||||
if (elfFile.fail()) return -1;
|
||||
|
||||
if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1;
|
||||
data.resize(shTable[i].sh_size);
|
||||
if (!elfFile.read(data.data(), shTable[i].sh_size)) return -1;
|
||||
|
||||
data = dataTmp;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -397,15 +394,12 @@ static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) {
|
|||
for (int i = 0; i < (int)shTable.size(); i++) {
|
||||
if ((int)shTable[i].sh_type != type) continue;
|
||||
|
||||
vector<char> dataTmp;
|
||||
dataTmp.resize(shTable[i].sh_size);
|
||||
|
||||
elfFile.seekg(shTable[i].sh_offset);
|
||||
if (elfFile.fail()) return -1;
|
||||
|
||||
if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1;
|
||||
data.resize(shTable[i].sh_size);
|
||||
if (!elfFile.read(data.data(), shTable[i].sh_size)) return -1;
|
||||
|
||||
data = dataTmp;
|
||||
return 0;
|
||||
}
|
||||
return -2;
|
||||
|
|
|
|||
Loading…
Reference in a new issue