jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
510 stars 51 forks source link

Simplify unsafe value struct vector access code generation #203

Closed TYoungSL closed 3 years ago

TYoungSL commented 3 years ago

Since the local fixed variable expires at the moment of scope closure, there's no guarantee that the return value is any safer with it's use.

Simplify this operation to just return the offset reference using a typed Unsafe.Add to a reference of the first field.

jamescourtney commented 3 years ago

This is a really good find, thank you!

codecov[bot] commented 3 years ago

Codecov Report

Merging #203 (3d62877) into master (7732270) will decrease coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #203      +/-   ##
==========================================
- Coverage   94.72%   94.71%   -0.01%     
==========================================
  Files         103      103              
  Lines        7558     7547      -11     
  Branches      661      661              
==========================================
- Hits         7159     7148      -11     
  Misses        300      300              
  Partials       99       99              
Impacted Files Coverage Δ
....Compiler/TypeDefinitions/ValueStructDefinition.cs 99.29% <100.00%> (-0.06%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7732270...3d62877. Read the comment docs.