Use implicit boolean casts; it doesn't hurt performance

This commit is contained in:
Andy Hanson
2016-06-20 11:30:48 -07:00
parent 166bc49f0c
commit 95cfaafdee
2 changed files with 38 additions and 38 deletions
+4 -4
View File
@@ -17,19 +17,19 @@ namespace ts {
}
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
if (node !== void 0) {
if (node) {
return cbNode(node);
}
}
function visitNodeArray<T>(cbNodes: (nodes: Node[]) => T, nodes: Node[]) {
if (nodes !== void 0) {
if (nodes) {
return cbNodes(nodes);
}
}
function visitEachNode<T>(cbNode: (node: Node) => T, nodes: Node[]) {
if (nodes !== void 0) {
if (nodes) {
for (const node of nodes) {
const result = cbNode(node);
if (result) {
@@ -44,7 +44,7 @@ namespace ts {
// embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
// a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned.
export function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T {
if (node === void 0) {
if (!node) {
return;
}
// The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray