Skip to content

Commit

Permalink
Wow. Much fast. Very zoom.
Browse files Browse the repository at this point in the history
  • Loading branch information
miniksa committed Jun 29, 2020
1 parent aa1ed0a commit 90a24b2
Showing 1 changed file with 64 additions and 11 deletions.
75 changes: 64 additions & 11 deletions src/host/_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;

goto EndWhile;
break;
case UNICODE_TAB:
{
case UNICODE_TAB: {
const ULONG TabSize = NUMBER_OF_SPACES_IN_TAB(XPosition);
XPosition = (SHORT)(XPosition + TabSize);
if (XPosition >= coordScreenBufferSize.X)
Expand Down Expand Up @@ -585,8 +584,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
FAIL_FAST_IF(!(WI_IsFlagSet(screenInfo.OutputMode, ENABLE_PROCESSED_OUTPUT)));
switch (*lpString)
{
case UNICODE_BACKSPACE:
{
case UNICODE_BACKSPACE: {
// move cursor backwards one space. overwrite current char with blank.
// we get here because we have to backspace from the beginning of the line
TempNumSpaces -= 1;
Expand Down Expand Up @@ -734,8 +732,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
}
break;
}
case UNICODE_TAB:
{
case UNICODE_TAB: {
const size_t TabSize = gsl::narrow_cast<size_t>(NUMBER_OF_SPACES_IN_TAB(cursor.GetPosition().X));
CursorPosition.X = (SHORT)(cursor.GetPosition().X + TabSize);

Expand Down Expand Up @@ -773,8 +770,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
Status = AdjustCursorPosition(screenInfo, CursorPosition, (dwFlags & WC_KEEP_CURSOR_VISIBLE) != 0, psScrollY);
break;
}
case UNICODE_CARRIAGERETURN:
{
case UNICODE_CARRIAGERETURN: {
// Carriage return moves the cursor to the beginning of the line.
// We don't need to worry about handling cr or lf for
// backspace because input is sent to the user on cr or lf.
Expand All @@ -784,8 +780,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
Status = AdjustCursorPosition(screenInfo, CursorPosition, (dwFlags & WC_KEEP_CURSOR_VISIBLE) != 0, psScrollY);
break;
}
case UNICODE_LINEFEED:
{
case UNICODE_LINEFEED: {
// move cursor to the next line.
pwchBuffer++;

Expand Down Expand Up @@ -1062,7 +1057,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
// - S_OK if successful.
// - S_OK if we need to wait (check if ppWaiter is not nullptr).
// - Or a suitable HRESULT code for math/string/memory failures.
[[nodiscard]] HRESULT ApiRoutines::WriteConsoleAImpl(IConsoleOutputObject& context,
[[nodiscard]] HRESULT WriteConsoleAImplForReals(IConsoleOutputObject& context,
const std::string_view buffer,
size_t& read,
std::unique_ptr<IWaitRoutine>& waiter) noexcept
Expand Down Expand Up @@ -1238,6 +1233,64 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
CATCH_RETURN();
}

static IConsoleOutputObject* obj = nullptr;
static std::condition_variable condvar;
static std::mutex bufflock;
static std::queue<std::string> buff;
void threadMethod()
{
size_t read = 0;
std::unique_ptr<IWaitRoutine> wait;

std::unique_lock<std::mutex> lk(bufflock, std::defer_lock);

std::string str;

while (true)
{
lk.lock();
condvar.wait(lk, [&] {
if (!buff.empty())
{
str = buff.front();
buff.pop();
return true;
}
return false;
});
lk.unlock();

LOG_IF_FAILED(WriteConsoleAImplForReals(*obj, str, read, wait));
}
}

static std::thread th(threadMethod);


[[nodiscard]] HRESULT ApiRoutines::WriteConsoleAImpl(IConsoleOutputObject& context,
const std::string_view buffer,
size_t& read,
std::unique_ptr<IWaitRoutine>& waiter) noexcept
try
{
read = buffer.size();
waiter.reset();

bufflock.lock();
if (!obj)
{
obj = &context;
}
buff.emplace(buffer);
bufflock.unlock();
condvar.notify_one();

return S_OK;
}
CATCH_RETURN()



// Routine Description:
// - Writes Unicode formatted data into the given console output object.
// - NOTE: This may be blocked for various console states and will return a wait context pointer if necessary.
Expand Down

1 comment on commit 90a24b2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • bufflock
  • condvar
To accept these changes, run the following commands
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect/alphabet.txt
.github/actions/spell-check/expect/expect.txt
.github/actions/spell-check/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"atg BKMK consoleaccessibility FFF hyperlink NRCS popclip remoting rerendered SCS shobjidl unfocuses xab xb xbc xca xce xdd xffff "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^($re)(?:$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect/90a24b20b8d27edbc8451936d215cf111cfe3164.txt";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"bufflock condvar nrcs Remoting Scs Shobjidl "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
git add .github/actions/spell-check/expect || echo '... you want to ensure .github/actions/spell-check/expect/90a24b20b8d27edbc8451936d215cf111cfe3164.txt is added to your repository...'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spell-check/dictionary/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spell-check/dictionary/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spell-check/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spell-check/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

⚠️ Reviewers

At present, the action that triggered this message will not show its ❌ in this PR unless the branch is within this repository.
Thus, you should make sure that this comment has been addressed before encouraging the merge bot to merge this PR.

Please sign in to comment.