So we learned the vector version is faster (when debugging is not enabled.
This commit is contained in:
parent
3a0d73eb79
commit
cfc197ac27
@ -4,7 +4,6 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
|
||||
typedef std::byte byte;
|
||||
typedef char sbyte;
|
||||
@ -39,8 +38,8 @@ class SHNFile{
|
||||
num = num3;
|
||||
}
|
||||
}
|
||||
std::list<byte>ReadBytes(int bytes){
|
||||
std::list<byte>byteArr={};
|
||||
std::vector<byte>ReadBytes(int bytes){
|
||||
std::vector<byte>byteArr={};
|
||||
for(int i=0;i<bytes;i++){
|
||||
if(marker<data.size()){
|
||||
byteArr.push_back(data[marker]);
|
||||
@ -52,47 +51,31 @@ class SHNFile{
|
||||
return byteArr;
|
||||
}
|
||||
byte ReadByte(){
|
||||
std::list<byte>b=ReadBytes(1);
|
||||
std::vector<byte>b=ReadBytes(1);
|
||||
if(b.size()>0){
|
||||
return b.front();
|
||||
return b[0];
|
||||
} else {
|
||||
return byte(0);
|
||||
}
|
||||
}
|
||||
uint16_t ReadUInt16(){
|
||||
std::list<byte>intBytes=ReadBytes(2);
|
||||
uint16_t numb = uint16_t(intBytes.back())<<8;
|
||||
intBytes.pop_back();
|
||||
numb |= uint16_t(intBytes.back());
|
||||
std::vector<byte>intBytes=ReadBytes(2);
|
||||
uint16_t numb = uint16_t(intBytes[1])<<8|uint16_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
int16_t ReadInt16(){
|
||||
std::list<byte>intBytes=ReadBytes(2);
|
||||
int16_t numb = int16_t(intBytes.back())<<8;
|
||||
intBytes.pop_back();
|
||||
numb |= int16_t(intBytes.back());
|
||||
std::vector<byte>intBytes=ReadBytes(2);
|
||||
int16_t numb = int16_t(intBytes[1])<<8|int16_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
uint32_t ReadUInt32(){
|
||||
std::list<byte>intBytes=ReadBytes(4);
|
||||
uint32_t numb = uint32_t(intBytes.back())<<24;
|
||||
intBytes.pop_back();
|
||||
numb |= uint32_t(intBytes.back())<<16;
|
||||
intBytes.pop_back();
|
||||
numb |= uint32_t(intBytes.back())<<8;
|
||||
intBytes.pop_back();
|
||||
numb |= uint32_t(intBytes.back());
|
||||
std::vector<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;
|
||||
}
|
||||
int ReadInt32(){
|
||||
std::list<byte>intBytes=ReadBytes(4);
|
||||
int numb = int(intBytes.back())<<24;
|
||||
intBytes.pop_back();
|
||||
numb |= int(intBytes.back())<<16;
|
||||
intBytes.pop_back();
|
||||
numb |= int(intBytes.back())<<8;
|
||||
intBytes.pop_back();
|
||||
numb |= int(intBytes.back());
|
||||
std::vector<byte>intBytes=ReadBytes(4);
|
||||
int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
struct Column{
|
||||
@ -101,38 +84,31 @@ class SHNFile{
|
||||
int length=0;
|
||||
};
|
||||
std::string ReadString(int bytes){
|
||||
std::list<byte>strBytes=ReadBytes(bytes);
|
||||
std::vector<byte>strBytes=ReadBytes(bytes);
|
||||
std::string str="";
|
||||
for(auto it=strBytes.begin();it!=strBytes.end();++it){
|
||||
if(*it!=byte(0)){
|
||||
str+=unsigned char(*it);
|
||||
for(int i=0;i<strBytes.size();i++){
|
||||
if(strBytes[i]!=byte(0)){
|
||||
str+=unsigned char(strBytes[i]);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
float ReadSingle(){
|
||||
std::list<byte>strBytes=ReadBytes(4);
|
||||
byte bytes[4];
|
||||
bytes[0]=strBytes.front();
|
||||
strBytes.pop_front();
|
||||
bytes[1]=strBytes.front();
|
||||
strBytes.pop_front();
|
||||
bytes[2]=strBytes.front();
|
||||
strBytes.pop_front();
|
||||
bytes[3]=strBytes.front();
|
||||
std::vector<byte>strBytes=ReadBytes(4);
|
||||
byte bytes[]={strBytes[0],strBytes[1],strBytes[2],strBytes[3]};
|
||||
float f;
|
||||
memcpy(&f,&bytes,sizeof(float));
|
||||
return f;
|
||||
}
|
||||
sbyte ReadSByte(){
|
||||
return sbyte(ReadBytes(1).front());
|
||||
return sbyte(ReadBytes(1)[0]);
|
||||
}
|
||||
std::string ReadString(){
|
||||
std::string str="";
|
||||
while(true){
|
||||
std::list<byte>byteArr=ReadBytes(1);
|
||||
if(byteArr.size()>0&&byteArr.front()!=byte(0)){
|
||||
str+=unsigned char(byteArr.front());
|
||||
std::vector<byte>byteArr=ReadBytes(1);
|
||||
if(byteArr.size()>0&&byteArr[0]!=byte(0)){
|
||||
str+=unsigned char(byteArr[0]);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user