Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Don't use sync*, as it is unimplemented in dart2wasm. #38149

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
Copy link
Contributor

@dkwingsmt dkwingsmt Dec 9, 2022

Choose a reason for hiding this comment

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

Can you help me fix this line by changing gen_web_keyboard_layouts to gen_web_locale_keymap? It was using the old library name. Make sure to change the tmpl too.

// https://github.com/microsoft/vscode/tree/ab7ccc9e872dfcdfc429f8f2815109ec0ca926e3/src/vs/workbench/services/keybinding/browser/keyboardLayouts
// https://github.com/microsoft/vscode/tree/422b581e3802e30cfb780c21d9cc1a2cd0c9f0aa/src/vs/workbench/services/keybinding/browser/keyboardLayouts
//
// Edit the following files instead:
//
Expand Down Expand Up @@ -100,16 +100,17 @@ bool isLetter(int charCode) {
///
/// This greatly reduces the entries needed in the final mapping.
int? heuristicMapper(String code, String key) {
// Digit code: return the digit.
// Digit code: return the digit by event code.
if (code.startsWith('Digit')) {
assert(code.length == 6);
return code.codeUnitAt(5); // The character immediately after 'Digit'
}
final int charCode = key.codeUnitAt(0);
// Non-ascii: return the goal (i.e. US mapping by event code).
if (key.length > 1 || !_isAscii(charCode)) {
return kLayoutGoals[code]?.codeUnitAt(0);
}
// Letter key: return the letter.
// Letter key: return the event key letter.
if (isLetter(charCode)) {
return key.toLowerCase().codeUnitAt(0);
}
Expand Down Expand Up @@ -167,22 +168,20 @@ class _StringStream {

Map<String, int> _unmarshallCodeMap(_StringStream stream) {
final int entryNum = stream.readIntAsVerbatim();
return Map<String, int>.fromEntries((() sync* {
for (int entryIndex = 0; entryIndex < entryNum; entryIndex += 1) {
yield MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar());
}
})());
return Map<String, int>.fromEntries(
Iterable<int>.generate(entryNum).map((final int index) =>
MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar())
));
Copy link
Contributor

Choose a reason for hiding this comment

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

if we're looking for performance, this would probably be even faster (you'd have to benchmark it to be sure) if we used a regular c-style for loop.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could/should use collection literal syntax, here!

return <String, int>{
  for (var i = 0; i < entryNum; i++)
    stream.readEventKey() : stream.readIntAsChar(),
};

Copy link
Contributor

Choose a reason for hiding this comment

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

I never thought it could be done this clean!

}

/// Decode a key mapping data out of the string.
Map<String, Map<String, int>> unmarshallMappingData(String compressed) {
final _StringStream stream = _StringStream(compressed);
final int eventCodeNum = stream.readIntAsVerbatim();
return Map<String, Map<String, int>>.fromEntries((() sync* {
for (int eventCodeIndex = 0; eventCodeIndex < eventCodeNum; eventCodeIndex += 1) {
yield MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream));
}
})());
return Map<String, Map<String, int>>.fromEntries(
Iterable<int>.generate(eventCodeNum).map((final int index) =>
MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream))
));
}

/// Data for [LocaleKeymap] on Windows.
Expand Down
18 changes: 8 additions & 10 deletions tools/gen_web_locale_keymap/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,20 @@ class _StringStream {

Map<String, int> _unmarshallCodeMap(_StringStream stream) {
final int entryNum = stream.readIntAsVerbatim();
return Map<String, int>.fromEntries((() sync* {
for (int entryIndex = 0; entryIndex < entryNum; entryIndex += 1) {
yield MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar());
}
})());
return Map<String, int>.fromEntries(
Iterable<int>.generate(entryNum).map((final int index) =>
MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar())
));
}

/// Decode a key mapping data out of the string.
Map<String, Map<String, int>> unmarshallMappingData(String compressed) {
final _StringStream stream = _StringStream(compressed);
final int eventCodeNum = stream.readIntAsVerbatim();
return Map<String, Map<String, int>>.fromEntries((() sync* {
for (int eventCodeIndex = 0; eventCodeIndex < eventCodeNum; eventCodeIndex += 1) {
yield MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream));
}
})());
return Map<String, Map<String, int>>.fromEntries(
Iterable<int>.generate(eventCodeNum).map((final int index) =>
MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream))
));
}

/*@@@ SHARED SEGMENT END @@@*/
Expand Down