Skip to content

Commit f754f66

Browse files
authored
faster string lookups (#4553)
1 parent ceb23c1 commit f754f66

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

Source/Csla.Web/CslaDataSource.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ internal static Type GetType(
138138
// explicit assembly name provided
139139
result = Type.GetType($"{typeName}, {typeAssemblyName}", true, true);
140140
}
141-
else if (typeName.IndexOf(",") > 0)
141+
else if (typeName.Contains(','))
142142
{
143143
// assembly qualified type name provided
144144
result = Type.GetType(typeName, true, true);

Source/Csla.Web/Design/CslaDataSourceConfiguration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ private void DiscoverTypes()
7070
// adds the types to the list
7171
foreach (Type type in types)
7272
{
73-
if (type.Assembly.FullName.Substring(0, type.Assembly.FullName.IndexOf(",")) != "Csla" &&
73+
if (type.Assembly.FullName.Substring(0, type.Assembly.FullName.IndexOf(',')) != "Csla" &&
7474
typeof(Core.IBusinessObject).IsAssignableFrom(type))
7575
{
7676
string name = type.AssemblyQualifiedName;
7777
if (name.Substring(name.Length - 19, 19) == "PublicKeyToken=null")
78-
name = name.Substring(0, name.IndexOf(",", name.IndexOf(",") + 1));
78+
name = name.Substring(0, name.IndexOf(',', name.IndexOf(',') + 1));
7979
TypeComboBox.Items.Add(name);
8080
}
8181
}

Source/Csla.Xaml.Shared/PropertyInfo.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ private void SetSource()
252252
{
253253
while (BindingPath.Contains(".") && Source != null)
254254
{
255-
var refName = BindingPath.Substring(0, BindingPath.IndexOf("."));
255+
var dotIndex = BindingPath.IndexOf('.');
256+
var refName = BindingPath.Substring(0, dotIndex);
256257
_sources.Add(new SourceReference(this, Source, refName));
257-
BindingPath = BindingPath.Substring(BindingPath.IndexOf(".") + 1);
258+
BindingPath = BindingPath.Substring(dotIndex + 1);
258259
Source = MethodCaller.CallPropertyGetter(Source, refName);
259260
}
260261
}
@@ -416,7 +417,7 @@ protected virtual void SetSource(object dataItem)
416417
}
417418
}
418419

419-
if (BindingPath.IndexOf('.') > 0)
420+
if (BindingPath.Contains('.'))
420421
BindingPath = BindingPath.Substring(BindingPath.LastIndexOf('.') + 1);
421422

422423
if (isDataLoaded)
@@ -460,18 +461,19 @@ protected object GetRealSource(object source, string bindingPath)
460461
{
461462
if (source is ICollectionView icv)
462463
source = icv.CurrentItem;
463-
if (source != null && bindingPath.IndexOf('.') > 0)
464+
var dotIndex = bindingPath.IndexOf('.');
465+
if (source != null && dotIndex > 0)
464466
{
465-
var firstProperty = bindingPath.Substring(0, bindingPath.IndexOf('.'));
467+
var firstProperty = bindingPath.Substring(0, dotIndex);
466468
var p = MethodCaller.GetProperty(source.GetType(), firstProperty);
467469
if (p != null)
468470
{
469471
source = GetRealSource(
470472
MethodCaller.GetPropertyValue(source, p),
471-
bindingPath.Substring(bindingPath.IndexOf('.') + 1));
473+
bindingPath.Substring(dotIndex + 1));
472474
}
473475
}
474-
476+
475477
return source;
476478
}
477479

@@ -484,15 +486,16 @@ protected PropertyPath GetRelativePath(object source, string bindingPath)
484486
{
485487
if (source != null)
486488
{
487-
if (bindingPath.IndexOf('.') > 0)
489+
var dotIndex = bindingPath.IndexOf('.');
490+
if (dotIndex > 0)
488491
{
489-
var firstProperty = bindingPath.Substring(0, bindingPath.IndexOf('.'));
492+
var firstProperty = bindingPath.Substring(0, dotIndex);
490493
var p = MethodCaller.GetProperty(source.GetType(), firstProperty);
491494

492495
if (p != null)
493496
return new PropertyPath(firstProperty);
494497
else
495-
return GetRelativePath(source, bindingPath.Substring(bindingPath.IndexOf('.') + 1));
498+
return GetRelativePath(source, bindingPath.Substring(dotIndex + 1));
496499
}
497500
else
498501
return new PropertyPath(bindingPath);

Source/Csla.Xaml.Shared/PropertyStatus.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ private void SetBindingValues()
220220
protected object GetRealSource(object source, string bindingPath)
221221
{
222222
var firstProperty = string.Empty;
223-
if (bindingPath.IndexOf('.') > 0)
224-
firstProperty = bindingPath.Substring(0, bindingPath.IndexOf('.'));
223+
var dotIndex = bindingPath.IndexOf('.');
224+
if (dotIndex > 0)
225+
firstProperty = bindingPath.Substring(0, dotIndex);
225226

226227
if (source is ICollectionView icv && firstProperty != "CurrentItem")
227228
source = icv.CurrentItem;
@@ -230,7 +231,7 @@ protected object GetRealSource(object source, string bindingPath)
230231
var p = MethodCaller.GetProperty(source.GetType(), firstProperty);
231232
return GetRealSource(
232233
MethodCaller.GetPropertyValue(source, p),
233-
bindingPath.Substring(bindingPath.IndexOf('.') + 1));
234+
bindingPath.Substring(dotIndex + 1));
234235
}
235236
else
236237
return source;

0 commit comments

Comments
 (0)