Add some speedup
This commit is contained in:
parent
82da8580c5
commit
0b3e857722
@ -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&{
|
||||
|
||||
@ -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){
|
||||
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,12 +223,11 @@ 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){
|
||||
auto time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user