@@ -786,20 +786,22 @@ namespace Concurrency { namespace streams
786
786
});
787
787
};
788
788
789
- auto update = [=](int_type ch) mutable -> pplx::task< bool >
789
+ auto update = [=](int_type ch) mutable
790
790
{
791
- if (ch == ::concurrency::streams::char_traits<CharType>::eof ()) return pplx::task_from_result ( false ) ;
792
- if (ch == delim) return pplx::task_from_result ( false ) ;
791
+ if (ch == ::concurrency::streams::char_traits<CharType>::eof ()) return false ;
792
+ if (ch == delim) return false ;
793
793
794
794
_locals->outbuf [_locals->write_pos ] = static_cast <CharType>(ch);
795
795
_locals->write_pos += 1 ;
796
796
797
797
if (_locals->is_full ())
798
798
{
799
- return flush ().then ([] { return true ; });
799
+ // Flushing synchronously because performance is terrible if we
800
+ // schedule an empty task. This isn't on a user's thread.
801
+ flush ().get ();
800
802
}
801
803
802
- return pplx::task_from_result ( true ) ;
804
+ return true ;
803
805
};
804
806
805
807
auto loop = pplx::details::do_while ([=]() mutable -> pplx::task<bool >
@@ -813,7 +815,10 @@ namespace Concurrency { namespace streams
813
815
break ;
814
816
}
815
817
816
- return update (ch);
818
+ if (!update (ch))
819
+ {
820
+ return pplx::task_from_result (false );
821
+ }
817
822
}
818
823
return buffer.bumpc ().then (update);
819
824
});
@@ -855,23 +860,25 @@ namespace Concurrency { namespace streams
855
860
856
861
auto update = [=](typename concurrency::streams::char_traits<CharType>::int_type ch) mutable
857
862
{
858
- if (ch == concurrency::streams::char_traits<CharType>::eof ()) return pplx::task_from_result ( false ) ;
859
- if (ch == ' \n ' ) return pplx::task_from_result ( false ) ;
863
+ if (ch == concurrency::streams::char_traits<CharType>::eof ()) return false ;
864
+ if (ch == ' \n ' ) return false ;
860
865
if (ch == ' \r ' )
861
866
{
862
867
_locals->saw_CR = true ;
863
- return pplx::task_from_result ( true ) ;
868
+ return true ;
864
869
}
865
870
866
871
_locals->outbuf [_locals->write_pos ] = static_cast <CharType>(ch);
867
872
_locals->write_pos += 1 ;
868
873
869
874
if (_locals->is_full ())
870
875
{
871
- return flush ().then ([] { return true ; });
876
+ // Flushing synchronously because performance is terrible if we
877
+ // schedule an empty task. This isn't on a user's thread.
878
+ flush ().wait ();
872
879
}
873
880
874
- return pplx::task_from_result ( true ) ;
881
+ return true ;
875
882
};
876
883
877
884
auto update_after_cr = [=] (typename concurrency::streams::char_traits<CharType>::int_type ch) mutable -> pplx::task<bool >
@@ -910,7 +917,10 @@ namespace Concurrency { namespace streams
910
917
if (ch == req_async)
911
918
break ;
912
919
913
- return update (ch);
920
+ if (!update (ch))
921
+ {
922
+ return pplx::task_from_result (false );
923
+ }
914
924
}
915
925
916
926
if (_locals->saw_CR )
@@ -1132,12 +1142,14 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
1132
1142
{
1133
1143
if (buffer.sbumpc () == req_async)
1134
1144
{
1135
- return buffer.nextc ().then ([](int_type) { return true ; });
1145
+ // Synchronously because performance is terrible if we
1146
+ // schedule an empty task. This isn't on a user's thread.
1147
+ buffer.nextc ().wait ();
1136
1148
}
1137
- return pplx::task_from_result ( true ) ;
1149
+ return true ;
1138
1150
}
1139
1151
1140
- return pplx::task_from_result ( false ) ;
1152
+ return false ;
1141
1153
};
1142
1154
1143
1155
auto loop = pplx::details::do_while ([=]() mutable -> pplx::task<bool >
@@ -1149,7 +1161,10 @@ pplx::task<void> concurrency::streams::_type_parser_base<CharType>::_skip_whites
1149
1161
if (ch == req_async)
1150
1162
break ;
1151
1163
1152
- return update (ch);
1164
+ if (!update (ch))
1165
+ {
1166
+ return pplx::task_from_result (false );
1167
+ }
1153
1168
}
1154
1169
return buffer.getc ().then (update);
1155
1170
});
0 commit comments