Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit fdb3d54

Browse files
committed
Return and use local object
For constructor and function return coherence
1 parent 253eb92 commit fdb3d54

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

src/Microsoft.AspNet.Http/Features/FeatureHelpers.cs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ public static T GetAndCache<T>(
1313
ref T cachedObject)
1414
{
1515
cache.CheckFeaturesRevision();
16-
if (cachedObject == null)
16+
17+
T obj = cachedObject;
18+
if (obj == null)
1719
{
18-
cachedObject = features.Get<T>();
20+
obj = features.Get<T>();
21+
cachedObject = obj;
1922
}
20-
return cachedObject;
23+
return obj;
2124
}
2225

2326
public static T GetOrCreateAndCache<T>(
@@ -27,16 +30,19 @@ public static T GetOrCreateAndCache<T>(
2730
ref T cachedObject)
2831
{
2932
cache.CheckFeaturesRevision();
30-
if (cachedObject == null)
33+
34+
T obj = cachedObject;
35+
if (obj == null)
3136
{
32-
cachedObject = features.Get<T>();
33-
if (cachedObject == null)
37+
obj = features.Get<T>();
38+
if (obj == null)
3439
{
35-
cachedObject = factory();
36-
features.Set(cachedObject);
40+
obj = factory();
41+
cachedObject = obj;
42+
features.Set(obj);
3743
}
3844
}
39-
return cachedObject;
45+
return obj;
4046
}
4147

4248
public static T GetOrCreateAndCache<T>(
@@ -46,16 +52,19 @@ public static T GetOrCreateAndCache<T>(
4652
ref T cachedObject)
4753
{
4854
cache.CheckFeaturesRevision();
49-
if (cachedObject == null)
55+
56+
T obj = cachedObject;
57+
if (obj == null)
5058
{
51-
cachedObject = features.Get<T>();
52-
if (cachedObject == null)
59+
obj = features.Get<T>();
60+
if (obj == null)
5361
{
54-
cachedObject = factory(features);
55-
features.Set(cachedObject);
62+
obj = factory(features);
63+
cachedObject = obj;
64+
features.Set(obj);
5665
}
5766
}
58-
return cachedObject;
67+
return obj;
5968
}
6069

6170
public static T GetOrCreateAndCache<T>(
@@ -66,16 +75,19 @@ public static T GetOrCreateAndCache<T>(
6675
ref T cachedObject)
6776
{
6877
cache.CheckFeaturesRevision();
69-
if (cachedObject == null)
78+
79+
T obj = cachedObject;
80+
if (obj == null)
7081
{
71-
cachedObject = features.Get<T>();
72-
if (cachedObject == null)
82+
obj = features.Get<T>();
83+
if (obj == null)
7384
{
74-
cachedObject = factory(request);
75-
features.Set(cachedObject);
85+
obj = factory(request);
86+
cachedObject = obj;
87+
features.Set(obj);
7688
}
7789
}
78-
return cachedObject;
90+
return obj;
7991
}
8092
}
8193
}

0 commit comments

Comments
 (0)