Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up WSDL parsing #1218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -40,7 +40,7 @@ export function splitQName<T>(nsName: T) {
};
}

const [topLevelName] = nsName.split('|');
const [topLevelName] = nsName.split('|', 1);

const prefixOffset = topLevelName.indexOf(':');

Expand Down
16 changes: 15 additions & 1 deletion src/wsdl/elements.ts
Expand Up @@ -65,6 +65,7 @@ export class Element {
public $targetNamespace?;
public children: Element[] = [];
public ignoredNamespaces;
public strict: boolean;
public name?: string;
public nsName?;
public prefix?: string;
Expand Down Expand Up @@ -124,7 +125,10 @@ export class Element {
return;
}

const ChildClass = this.allowedChildren[splitQName(nsName).name];
let ChildClass = this.allowedChildren[splitQName(nsName).name];
if (ChildClass == null && !this.strict) {
ChildClass = UnexpectedElement;
}
if (ChildClass) {
const child = new ChildClass(nsName, attrs, options, schemaXmlns);
child.init();
Expand Down Expand Up @@ -171,14 +175,24 @@ export class Element {
this.valueKey = options.valueKey || '$value';
this.xmlKey = options.xmlKey || '$xml';
this.ignoredNamespaces = options.ignoredNamespaces || [];
this.strict = options.strict || false;
} else {
this.valueKey = '$value';
this.xmlKey = '$xml';
this.ignoredNamespaces = [];
this.strict = false;
}
}
}

export class UnexpectedElement extends Element {
public startElement(stack: Element[], nsName: string, attrs, options: IWsdlBaseOptions, schemaXmlns) {
const child = new UnexpectedElement(nsName, attrs, options, schemaXmlns);
child.init();
stack.push(child);
}
Comment on lines +189 to +193
Copy link
Author

Choose a reason for hiding this comment

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

This short-circuits the allowedChildren lookup.

}

export class ElementElement extends Element {
public readonly allowedChildren = buildAllowedChildren([
'annotation',
Expand Down
2 changes: 1 addition & 1 deletion test/client-test.js
Expand Up @@ -500,7 +500,7 @@ var fs = require('fs'),
assert.ok(result);
assert.ok(client.lastResponse);
assert.ok(client.lastResponseHeaders);
assert.ok(client.lastElapsedTime);
assert.ok(client.lastElapsedTime !== undefined);
Copy link
Author

Choose a reason for hiding this comment

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

This seems to be flaky on my machine because it's 0 sometimes (and more likely with this change), which is falsy. However, we're only interested in the existence of the value.


done();
}, { time: true }, { 'test-header': 'test' });
Expand Down