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