You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve how byte arrays are created in ZipHelper.GetEncodedTruncatedBytesFromString #64767
area-System.IO.CompressionenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issue
internalstaticbyte[]GetEncodedTruncatedBytesFromString(string?text,Encoding?encoding,intmaxBytes,outboolisUTF8){if(string.IsNullOrEmpty(text)){isUTF8=false;returnArray.Empty<byte>();}encoding??=GetEncoding(text);isUTF8=encoding.CodePage==65001;if(maxBytes==0)// No truncation{returnencoding.GetBytes(text);}varbyteCount=encoding.GetByteCount(text);varbuffer=ArrayPool<byte>.Shared.Rent(byteCount);try{encoding.GetBytes(text,0,text.Length,buffer,0);}catch(Exception){ArrayPool<byte>.Shared.Return(buffer);throw;}byte[]bytes;if(isUTF8){inttotalCodePoints=0;foreach(Runeruneintext.EnumerateRunes()){if(totalCodePoints+rune.Utf8SequenceLength>maxBytes){break;}totalCodePoints+=rune.Utf8SequenceLength;}Debug.Assert(totalCodePoints>0);Debug.Assert(totalCodePoints<=byteCount);bytes=buffer[0..totalCodePoints];ArrayPool<byte>.Shared.Return(buffer);returnbytes;}bytes=buffer[0..Math.Min(maxBytes,byteCount)];ArrayPool<byte>.Shared.Return(buffer);returnbytes;}
Yes, I think that's what was being asked in the PR, @LeaFrock, thank you so much. Yes, if you can send a PR, that would be awesome. I'll assign the issue to you. Tag @ViktorHofer and I when it's up so we can review it.
area-System.IO.CompressionenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issue
Activity
LeaFrock commentedon Jun 25, 2023
Is this what you want? Maybe I can make a PR.
carlossanlop commentedon Jul 5, 2023
Yes, I think that's what was being asked in the PR, @LeaFrock, thank you so much. Yes, if you can send a PR, that would be awesome. I'll assign the issue to you. Tag @ViktorHofer and I when it's up so we can review it.