Skip to content

Commit 19dbd12

Browse files
fixed performance issue with regex compilation (#14)
fixed xhr status text not working in Chrome (#13)
1 parent 16e3dce commit 19dbd12

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

AjaxPro/AjaxPro.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31729.503
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32228.430
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AjaxPro", "AjaxPro.csproj", "{9AD42568-07A4-4D8B-9C6D-1FD54683EF4B}"
77
EndProject

AjaxPro/Attributes/AjaxNamespaceAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
*/
3232
using System;
33+
using System.Text.RegularExpressions;
3334

3435
namespace AjaxPro
3536
{
@@ -40,7 +41,7 @@ namespace AjaxPro
4041
public class AjaxNamespaceAttribute : Attribute
4142
{
4243
private string _clientNS = null;
43-
private System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("^[a-zA-Z_]{1}([a-zA-Z_]*([\\d]*)?)*((\\.)?[a-zA-Z_]+([\\d]*)?)*$", System.Text.RegularExpressions.RegexOptions.Compiled);
44+
private static readonly Regex r = new Regex("^[a-zA-Z_]{1}([a-zA-Z_]*([\\d]*)?)*((\\.)?[a-zA-Z_]+([\\d]*)?)*$", System.Text.RegularExpressions.RegexOptions.Compiled);
4445

4546
/// <summary>
4647
/// This attribute can be used to specified a different namespace for the client-side representation.

AjaxPro/JSON/Converters/DateTimeConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace AjaxPro
4747
/// </summary>
4848
public class DateTimeConverter : IJavaScriptConverter
4949
{
50-
private Regex r = new Regex(@"(\d{4}),(\d{1,2}),(\d{1,2}),(\d{1,2}),(\d{1,2}),(\d{1,2}),(\d{1,3})", RegexOptions.Compiled);
50+
private static readonly Regex r = new Regex(@"(\d{4}),(\d{1,2}),(\d{1,2}),(\d{1,2}),(\d{1,2}),(\d{1,2}),(\d{1,3})", RegexOptions.Compiled);
5151
private double UtcOffsetMinutes = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes;
5252

5353
/// <summary>

AjaxPro/JSON/JavaScriptUtil.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
using System.Xml;
4545
using System.Text;
4646
using System.Globalization;
47+
using System.Text.RegularExpressions;
4748

4849
namespace AjaxPro
4950
{
@@ -52,7 +53,7 @@ namespace AjaxPro
5253
/// </summary>
5354
public sealed class JavaScriptUtil
5455
{
55-
private static System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"\w+|\W+", System.Text.RegularExpressions.RegexOptions.Compiled);
56+
private static readonly Regex r = new Regex(@"\w+|\W+", System.Text.RegularExpressions.RegexOptions.Compiled);
5657

5758
/// <summary>
5859
/// Get the client-side JavaScript namespace script.

AjaxPro/Utilities/Constant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public sealed class Constant
5252
/// <summary>
5353
/// The assembly version.
5454
/// </summary>
55-
public const string AssemblyVersion = "22.02.03.1";
55+
public const string AssemblyVersion = "22.3.20.1";
5656
}
5757
}

AjaxPro/core.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ AjaxPro.Request.prototype = {
343343
}
344344
var res = this.getEmptyRes();
345345
//Ignore empty statustext to be http2 compatible
346-
if (this.xmlHttp.status == 200 && this.xmlHttp.statusText == "OK" || !this.xmlHttp.statusText) {
346+
if (this.xmlHttp.status == 200 || !this.xmlHttp.statusText) {
347347
res = this.createResponse(res);
348348
} else {
349349
res = this.createResponse(res, true);
@@ -386,11 +386,15 @@ AjaxPro.Request.prototype = {
386386
},
387387
timeout: function () {
388388
this.duration = new Date().getTime() - this.__start;
389-
var r = this.onTimeout(this.duration, this);
390-
if (typeof r == "undefined" || r != false) {
389+
if (this.onTimeout == null || typeof (this.onTimeout) != "function") {
391390
this.abort();
392391
} else {
393-
this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod);
392+
var r = this.onTimeout(this.duration, this);
393+
if (typeof r == "undefined" || r != false) {
394+
this.abort();
395+
} else {
396+
this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod);
397+
}
394398
}
395399
},
396400
invoke: function (method, args, callback, context) {

0 commit comments

Comments
 (0)