Add some speedup

This commit is contained in:
Rexy712 2019-05-19 10:54:15 -07:00
parent 82da8580c5
commit 0b3e857722
2 changed files with 14 additions and 11 deletions

View File

@ -96,9 +96,7 @@ auto printer_base<Derived>::print(const wchar_t* s)noexcept(noexcept(std::declva
}
template<class Derived>
auto printer_base<Derived>::print(char s) -> Derived&{
wchar_t tmp;
mbstowcs(&tmp, &s, 1);
return print(tmp);
return print(static_cast<wchar_t>(s));
}
template<class Derived>
auto printer_base<Derived>::print(const char* s) -> Derived&{

View File

@ -135,8 +135,9 @@ void nonprinting_notation(int in, char* dest){
}
//Use the given type of printer to output the contents of files and/or stdin
//treat the file as text in the current locale
template<class Printer>
int print_normal_files(cmd_args& args){
int print_normal_files(const cmd_args& args){
int ret = 0;
Printer p(args);
for(size_t i = 0;i < args.filenames.size();++i){
@ -169,8 +170,9 @@ int print_normal_files(cmd_args& args){
return ret;
}
//Use the given type of printer to output the contents of files and/or stdin
//Treat the file as a binary file (ascii)
template<class Printer>
int print_binary_files(cmd_args& args){
int print_binary_files(const cmd_args& args){
int ret = 0;
Printer p(args);
for(size_t i = 0;i < args.filenames.size();++i){
@ -191,13 +193,17 @@ int print_binary_files(cmd_args& args){
ret = 2;
continue;
}
for(int in;(in = fgetc(fp)) != WEOF;)
if(args.nonprinting){
if(args.nonprinting){
for(int in;(in = fgetc(fp)) != WEOF;){
char tmp[5];
nonprinting_notation(in, tmp);
p.print(tmp);
}else
}
}else{
for(int in;(in = fgetc(fp)) != WEOF;){
p.print(static_cast<char>(in));
}
}
p.reset();
fclose(fp);
}
@ -217,11 +223,10 @@ int print_files(cmd_args& args){
return 0;
}
if(args.treatbinary){
if(args.treatbinary)
return print_binary_files<Printer>(args);
}else{
else
return print_normal_files<Printer>(args);
}
}
auto get_time(void){