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>
|
template<class Derived>
|
||||||
auto printer_base<Derived>::print(char s) -> Derived&{
|
auto printer_base<Derived>::print(char s) -> Derived&{
|
||||||
wchar_t tmp;
|
return print(static_cast<wchar_t>(s));
|
||||||
mbstowcs(&tmp, &s, 1);
|
|
||||||
return print(tmp);
|
|
||||||
}
|
}
|
||||||
template<class Derived>
|
template<class Derived>
|
||||||
auto printer_base<Derived>::print(const char* s) -> 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
|
//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>
|
template<class Printer>
|
||||||
int print_normal_files(cmd_args& args){
|
int print_normal_files(const cmd_args& args){
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
Printer p(args);
|
Printer p(args);
|
||||||
for(size_t i = 0;i < args.filenames.size();++i){
|
for(size_t i = 0;i < args.filenames.size();++i){
|
||||||
@ -169,8 +170,9 @@ int print_normal_files(cmd_args& args){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//Use the given type of printer to output the contents of files and/or stdin
|
//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>
|
template<class Printer>
|
||||||
int print_binary_files(cmd_args& args){
|
int print_binary_files(const cmd_args& args){
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
Printer p(args);
|
Printer p(args);
|
||||||
for(size_t i = 0;i < args.filenames.size();++i){
|
for(size_t i = 0;i < args.filenames.size();++i){
|
||||||
@ -191,13 +193,17 @@ int print_binary_files(cmd_args& args){
|
|||||||
ret = 2;
|
ret = 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for(int in;(in = fgetc(fp)) != WEOF;)
|
|
||||||
if(args.nonprinting){
|
if(args.nonprinting){
|
||||||
|
for(int in;(in = fgetc(fp)) != WEOF;){
|
||||||
char tmp[5];
|
char tmp[5];
|
||||||
nonprinting_notation(in, tmp);
|
nonprinting_notation(in, tmp);
|
||||||
p.print(tmp);
|
p.print(tmp);
|
||||||
}else
|
}
|
||||||
|
}else{
|
||||||
|
for(int in;(in = fgetc(fp)) != WEOF;){
|
||||||
p.print(static_cast<char>(in));
|
p.print(static_cast<char>(in));
|
||||||
|
}
|
||||||
|
}
|
||||||
p.reset();
|
p.reset();
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@ -217,11 +223,10 @@ int print_files(cmd_args& args){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args.treatbinary){
|
if(args.treatbinary)
|
||||||
return print_binary_files<Printer>(args);
|
return print_binary_files<Printer>(args);
|
||||||
}else{
|
else
|
||||||
return print_normal_files<Printer>(args);
|
return print_normal_files<Printer>(args);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_time(void){
|
auto get_time(void){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user