Commit Graph
1374 Commits
Author SHA1 Message Date
Jon Hanna dcae8e220d Some optimisations to async reading. (#1171)
MoveToContentAsync is often called in states where it will immediately
return true without any reading. In this case return AsyncUtils.True
avoiding allocation or async state-machine.

DoReadAsync is a very heavily hit method, and can often be fulfilled
without creating another state machine, so do this.

The remaining looping async case is the only use of ParsePostValueAsync,
so inline it into the calling method, so there is one less task
allocation.

Return value of EatWhitespaceAsync is never used, returning void reduces
the number of locals an hence the size of the state-machine. Do the same
for EatWhitespace though the impact is less.
2017-01-13 20:41:18 +13:00
James Newton-King ba04246a16 -Improved SplitFullyQualifiedTypeName allocations 2017-01-13 01:07:13 +13:00
Florian Greinacher b8e60c773b Change ifdefs to be by feature, not by platform (#1146)
* First pass

* Second pass

* Third pass

* Temporarily change build script to build only portable

* Add portable features for release build

* Add feature constants to build script

* Add more feature constants to build script

* Fix build issues

* Fix build issues

* Get rid of constants in build.ps1

* HAVE_NUMERICS -> HAVE_BIG_INTEGER

* Remove HAVE_NULLABLE

* Remove HAVE_NUMERICS from csprojs

* Add missing ifdef

* Add feature defines to pj

* Re-enable netstd builds

* Fix defines in pj

* Trying to get better build outputs

* Trying to get the build error

* Use newer cli

* Address review feedback; make netstd build work

* Introduce HAVE_DB_NULL_TYPE

* Adapt to upstream changes; address remaining review feedback

* Adapt to upstream changes; address remaining review feedback

* Rename some constants for constistency

* Address review feedback

* -Fixed build with signed assembly

* Fix merge erorr

* Address review feedback

* Introduce HAVE_NON_SERIALIZED_ATTRIBUTE

* HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE
2017-01-12 11:07:02 +13:00
James Newton-King eb96cb9f62 Merge pull request #1159 from JonHanna/fault_on_fault
Don't eat exceptions from faulted Tasks.
2017-01-11 09:30:42 +13:00
Jon Hanna 82bfde49e0 Don't eat exceptions from faulted Tasks.
If explicitly testing for IsCompleted then one must also test for
IsFaulted and if not handling the exception, return the faulted Task.
2017-01-10 11:12:46 +00:00
James Newton-King 21f4d95263 Merge pull request #1158 from JonHanna/pass_cancellation
Pass CancellationToken in JObject and JConstructor.WriteToAsync
2017-01-10 08:30:54 +13:00
Jon Hanna dd8d6217a1 Pass CancellationToken in JObject and JConstructor.WriteToAsync
Missed by mistake.
2017-01-09 11:28:41 +00:00
James Newton-King 0654fa5833 -Derp 2017-01-09 23:44:08 +13:00
James Newton-King b29b7e8483 -Derp 2017-01-09 23:44:08 +13:00
James Newton-King 08eb6845e2 -Async write performance 2017-01-09 23:44:08 +13:00
James Newton-King 5fefa723ad -Perf tests 2017-01-09 23:44:08 +13:00
Jon Hanna c9b2ec8055 Async JToken methods 2017-01-09 23:44:08 +13:00
James Newton-King dde1d905df -Build 2017-01-09 17:16:56 +13:00
Jon Hanna 7a93892d03 Optimise WriteEscapedJavaScriptString
Skip attempting write when string is empty.

FirstCharToEscape was introduced for the async version and gives a
faster means to identify the first block before any escaping, so may as
well use it here too.

Conversely, WriteEscapedStringThroughBuffer was introduced to share
code between the sync and async versions, but later optimisations meant
it was no longer used by the async. Inline the code back again.
2017-01-09 17:12:00 +13:00
James Newton-King de82488549 -Minor code cleanup
-Fixed CA warning
2017-01-09 16:46:11 +13:00
James Newton-King 6c7e41537b Merge pull request #1153 from JonHanna/shortcircuit_same_compared
Short-circuit on reference equality in ValueEquals and JValue.Compare
2017-01-09 15:17:53 +13:00
James Newton-King ba79136e4e Merge pull request #1151 from JonHanna/singleton_empty_array
Use singleton for zero-element arrays.
2017-01-09 15:11:14 +13:00
Jon Hanna ff3bfaf51b Use singleton for zero-element arrays.
Create an easily-inlinable method that accesses the array used
by Enumerable.Empty (and hence not just shared within this project
but likely with the client assembly or other libraries it uses)
and use it anywhere a zero-element array is used, reducing allocations.
2017-01-09 01:50:03 +00:00
Jon Hanna ea6a21c4f3 Optimise DynamicProxyMetaObject (#1152)
* Remove unnecessary ToArray call.

* Remove Value property.

One use compares with null, so cast to T is a waste.

This leaves just one other use, so it can be inlined.

* Remove _dontFallbackFirst

Is always true. Remove it and branches for it being false.

* Don't use Expression.Convert to reference types to object.

The end-result is a no-op, so don't waste the allocation.
2017-01-09 14:44:56 +13:00
Jon Hanna f1aa441b62 Short-circuit on reference equality in ValueEquals and JValue.Compare
Covers the both-null case previously checked for, so no extra cost, and
skips all further work.

Also make two `is` checks a null-check after `as`.
2017-01-09 01:18:02 +00:00
Jon Hanna cad2ec3a09 Reduce enumeration of rightResults in BooleanQueryExpression.IsMatch (#1155)
If Operator is Exists or leftResults is empty don't obtain rightResults,
as not relevant.

Otherwise if rightResults is not an ICollection<JToken> load it into an
List so it won't be recomputed on each enumeration of leftResults.
2017-01-09 14:12:49 +13:00
Jon Hanna ec2659e3ad Merge ifs into following switch on same expression in ReadAsBytes (#1147) 2017-01-09 14:01:18 +13:00
Jon Hanna 859d12e338 Remove redundant call to Cast<>() (#1154) 2017-01-09 10:38:36 +13:00
Jon Hanna cc7f5d80eb Merge 10 branches on propertyAttribute != null into one. (#1149) 2017-01-08 15:48:32 +13:00
Jon Hanna f4c17aedb2 Coalesce nulls rather than null test where applicable. (#1150) 2017-01-08 15:36:31 +13:00
Jon Hanna 2061a8bb9a Simplify Equals override in JValue (#1148)
otherValue == null, including obj == null, both result in false and
will also result in false if continued into the Equals(JValue) method
in the first branch, so having separate branches is just extra work.
2017-01-08 15:33:03 +13:00
Jon Hanna ed99856139 Use singleons for Null, Undefined, true and false BsonTokens. (#1145)
With Null and Undefined BsonValue's, one such value is
indistinguishable from another, so singletons can be used for them,
reducing allocations.

With BsonValue containing booleans as well as there being only so
there's a similar advantage with the extra benefit that if there is
only one true value then a reference-equals check can be used instead
of unboxing to determine the value to write.
2017-01-08 09:10:10 +13:00
Jon Hanna 218c25c859 Call nullable WriteValue overloads in TraceJsonWriter (#1139)
Fixes #1138
2017-01-07 20:25:46 +13:00
Jon Hanna 260dfedac5 Don't throw on BsonWriter.WriteValue for null Uri or byte[] (#1143)
Fixes #1142
2017-01-07 18:38:38 +13:00
Jon Hanna 0b187df8cb Null-coalesce within enumerable types. (#1136)
Reduces field-access.
2017-01-07 08:13:04 +13:00
Jon Hanna f663060005 Asynchronous methods in readers and writers. (#1122)
Contributes to #650
2017-01-06 15:33:39 +13:00
James Newton-King 211b3b0db2 Merge pull request #1132 from JonHanna/favour_as_over_is
Replace is-and-cast with as-and-nullcheck
2017-01-05 17:00:42 +13:00
James Newton-King 5bd69fe8be Merge pull request #1131 from JonHanna/opt_extensions_values
Optimise Extensions.Values
2017-01-05 16:58:12 +13:00
Jon Hanna a95665b481 Replace is-and-cast with as-and-nullcheck
Gives slightly better performance, so applying across the board
adds up.
2017-01-05 01:52:04 +00:00
Jon Hanna 4db6579593 Optimise Extensions.Values
Branch on key being null or not once, rather than once per loop.

Remove up-cast of token to JToken to allow jitter to either elide
JValue path if impossible or turn into null-test when inevitable.

Replace is-and-cast with as-and-null-test for quicker cast in cases
where cast is still done.
2017-01-05 00:49:54 +00:00
James Newton-King 008a3c7655 Merge pull request #1126 from JonHanna/remove_list_array
Remove some unnecessary list and array allocations.
2017-01-05 11:32:37 +13:00
Jon Hanna d408066f64 Remove some unnecessary list and array allocations. 2017-01-04 22:22:26 +00:00
James Newton-King 306c3a812b Merge pull request #1125 from JonHanna/null_propogate
Use null-propogation where applicable and useful.
2017-01-05 11:15:49 +13:00
James Newton-King 60651dbd59 Merge pull request #1127 from stakx/issue-typos
Fix typos
2017-01-05 11:06:24 +13:00
James Newton-King 1a70298696 Merge pull request #1130 from JonHanna/linq_bridge_optimise
Linq bridge optimise
2017-01-05 11:01:06 +13:00
Jon Hanna f5c64fdd09 Optimise linqbridge Select 2017-01-04 16:20:58 +00:00
Jon Hanna 896448860a Optimise LinqBridge.Enumerable.Where 2017-01-04 15:48:12 +00:00
Jon Hanna c003ad0d98 Optimise decimal predicate sum 2017-01-04 15:45:48 +00:00
Jon Hanna 32d8b4a68a Optimise LinqBridge Any 2017-01-04 15:45:06 +00:00
Jon Hanna dbc7374995 Optimise LinqBridge Count 2017-01-04 15:17:22 +00:00
Jon Hanna e08d1f7524 Optimise ToArray for list source 2017-01-04 15:01:48 +00:00
Jon Hanna 5bd4521b53 Load stack for Reverse using enumerable-taking ctor 2017-01-04 14:53:16 +00:00
Jon Hanna 1829b71255 Optimise LinqBridge.Enumerable.Cast for direct cast available.
(This changes the behaviour to return same type, but framework Linq has
the same optimisation).
2017-01-04 14:52:30 +00:00
stakx 8639ac94ae Typos
Running a spell checker on the whole solution revealed a couple more
typos. This fixes all of those (although internal // line comments are
mostly left alone).

Additionally, convert a very few string.Format occurrences to the pre-
dominant .FormatWith pattern and fix some incorrect message strings.
2017-01-04 03:01:26 +01:00
Jon Hanna b567a066e6 Use null-propogation where applicable and useful.
Primarily where it means one fewer field-access or simplifies
event delegate invocation, though one or two cases have just the
lesser advantage of allowing an IL stack dup rather than local access.
2017-01-03 20:08:12 +00:00