Comments (7)
This is just a little performance. I think there is an alternative method for targets that don't like unsafe.
from sharpcompress.
It seems that in my pull request I didn't take into consideration that platform can be big-endian as well, which will make BitConverter.GetBytes() to be wrong when running on such platforms (if indeed WriteLittleEndian() should write bytes using little-endian method). Can some one look into this closer maybe. From what I understand code will need to be modified like following to work properly on all platforms:
public static void WriteLittleEndian(byte[] array, int pos, short value)
{
byte[] newBytes = BitConverter.GetBytes(value);
if (!BitConverter.IsLittleEndian)
Array.Reverse(newBytes);
Array.Copy(newBytes, 0, array, pos, newBytes.Length);
}
It will most likely not affect any real code, but still better to do it right.
from sharpcompress.
I believe the algorithms using that operate in a VM of sorts. Little Endianness is expected regardless of platform.
from sharpcompress.
@haykpetros , why make it so overly complicated using BitConverter, if
statements, Array.Copy and Array.Reverse? If you want to write a short value (16bit) into a byte array in little-endian with only managed/safe code, just simply do:
array[pos] = (byte) (value & 0xFF); array[pos+1] = (byte) (value >> 8);
from sharpcompress.
@elgonzo, I personally think it is more readable. There are two overrides to this method, one accepting short another accepting int. Though I don't have personally preference if you write it like in your example using casting, but I am always inclined to make code readable for everyone.
from sharpcompress.
I don't know how often this method is called, but allocating a new array (via BitConverter.GetBytes
) for every number written probably is gonna hurt performance. Considering the point of the original unsafe code was performance, your suggestion sounds like a bad idea.
The suggestion of elgonzo is what one should do if unsafe code isn't allowed.
from sharpcompress.
@weltkante well, this particular suggestion wasn't about performance. Originally my suggestion was to remove conditional compilation as it wasn't necessary. I don't have objections to what @elgonzo said, but based on testing on my machine I saw no performance gains.
from sharpcompress.
Related Issues (20)
- Target Frameworks HOT 1
- Library-wise exception type HOT 2
- WriteEntryToDirectory with GZipReader fails HOT 4
- Large folder (> 3Gib) throws exception "Stream was too long" HOT 1
- Tar: Missing support for Pax extended file headers
- False positive in tar detection HOT 1
- Problem with Microsoft.SourceLink.GitHub dependency HOT 10
- Suggestion: Work with open files HOT 1
- root folder in zip HOT 2
- security policy HOT 4
- Hang while opening BZip2 HOT 4
- HttpBaseStream Gzip extract - NotSupportedException HOT 4
- Unable to open a certain rar file HOT 1
- `GZipArchive`s created from a stream have `ArchiveType` set to `Tar` instead of `GZip` HOT 1
- Add LongLink Support to Tar reading
- Problems discovered while decompressing PosrgresSQL HOT 4
- OS specific invalid characters are causing extraction to corrupt file HOT 7
- Reading a rar stream from a rar file gets NotSupportedException Specified method is not supported HOT 1
- compatibility with non-standard zip formats HOT 3
- How to quickly modify the file name in a zip file, as there is only one file in a zip file. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpcompress.