Optimize to use the same vector repeatedly and return a reference to it instead of copying.
This commit is contained in:
parent
e516dbf65a
commit
d0cc51f224
@ -81,6 +81,8 @@ private:
|
||||
std::vector<Column>columns;
|
||||
std::vector<std::vector<Data>>contents;
|
||||
std::string filename;
|
||||
std::vector<std::byte>readArr;
|
||||
std::byte*fileMarker=0;
|
||||
public:
|
||||
void Load(std::string file);
|
||||
void Save();
|
||||
@ -140,8 +142,8 @@ void SHNFile::Decrypt(){
|
||||
num = num3;
|
||||
}
|
||||
}
|
||||
std::vector<std::byte>SHNFile::ReadBytes(int bytes){
|
||||
std::vector<std::byte>byteArr={};
|
||||
std::vector<std::byte>&SHNFile::ReadBytes(int bytes){
|
||||
readArr.clear();
|
||||
for(int i=0;i<bytes;i++){
|
||||
if(marker<data.size()){
|
||||
byteArr.push_back(data[marker]);
|
||||
@ -153,7 +155,7 @@ std::vector<std::byte>SHNFile::ReadBytes(int bytes){
|
||||
return byteArr;
|
||||
}
|
||||
std::byte SHNFile::ReadByte(){
|
||||
std::vector<std::byte>b=ReadBytes(1);
|
||||
std::vector<std::byte>&b=ReadBytes(1);
|
||||
if(b.size()>0){
|
||||
return b[0];
|
||||
} else {
|
||||
@ -167,7 +169,7 @@ void SHNFile::WriteSByte(std::ofstream&f,sbyte b){
|
||||
f<<char(b);
|
||||
}
|
||||
uint16_t SHNFile::ReadUInt16(){
|
||||
std::vector<std::byte>intBytes=ReadBytes(2);
|
||||
std::vector<std::byte>&intBytes=ReadBytes(2);
|
||||
uint16_t numb = uint16_t(intBytes[1])<<8|uint16_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -175,7 +177,7 @@ void SHNFile::WriteUInt16(std::ofstream&f,uint16_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF);
|
||||
}
|
||||
int16_t SHNFile::ReadInt16(){
|
||||
std::vector<std::byte>intBytes=ReadBytes(2);
|
||||
std::vector<std::byte>&intBytes=ReadBytes(2);
|
||||
int16_t numb = int16_t(intBytes[1])<<8|int16_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -183,7 +185,7 @@ void SHNFile::WriteInt16(std::ofstream&f,int16_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF);
|
||||
}
|
||||
uint32_t SHNFile::ReadUInt32(){
|
||||
std::vector<std::byte>intBytes=ReadBytes(4);
|
||||
std::vector<std::byte>&intBytes=ReadBytes(4);
|
||||
uint32_t numb = uint32_t(intBytes[3])<<24|uint32_t(intBytes[2])<<16|uint32_t(intBytes[1])<<8|uint32_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -191,12 +193,12 @@ void SHNFile::WriteUInt32(std::ofstream&f,uint32_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF)<<unsigned char((val>>16)&0xFF)<<unsigned char((val>>24)&0xFF);
|
||||
}
|
||||
int SHNFile::Read(){
|
||||
std::vector<std::byte>intBytes=ReadBytes(4);
|
||||
std::vector<std::byte>&intBytes=ReadBytes(4);
|
||||
int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
int32_t SHNFile::ReadInt32(){
|
||||
std::vector<std::byte>intBytes=ReadBytes(4);
|
||||
std::vector<std::byte>&intBytes=ReadBytes(4);
|
||||
int32_t numb = int32_t(intBytes[3])<<24|int32_t(intBytes[2])<<16|int32_t(intBytes[1])<<8|uint32_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -204,7 +206,7 @@ void SHNFile::WriteInt32(std::ofstream&f,int32_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF)<<unsigned char((val>>16)&0xFF)<<unsigned char((val>>24)&0xFF);
|
||||
}
|
||||
std::string SHNFile::ReadString(int bytes){
|
||||
std::vector<std::byte>strBytes=ReadBytes(bytes);
|
||||
std::vector<std::byte>&strBytes=ReadBytes(bytes);
|
||||
std::string str="";
|
||||
for(int i=0;i<strBytes.size();i++){
|
||||
if(strBytes[i]!=std::byte(0)){
|
||||
|
Loading…
x
Reference in New Issue
Block a user