cosmetics

master
UbitUmarov 2020-05-13 14:51:05 +01:00
parent f15c6be20c
commit 4c7107dfda
2 changed files with 75 additions and 72 deletions

View File

@ -582,25 +582,36 @@ namespace OpenSim.Framework
/// <summary> /// <summary>
/// Convert a NameValueCollection into a query string. This is the /// Convert a NameValueCollection into a query string. This is the
/// inverse of HttpUtility.ParseQueryString() /// not exactly the inverse of HttpUtility.ParseQueryString()
/// </summary> /// </summary>
/// <param name="parameters">Collection of key/value pairs to convert</param> /// <param name="parameters">Collection of key/value pairs to convert</param>
/// <returns>A query string with URL-escaped values</returns> /// <returns>A query string with URL-escaped values</returns>
public static string BuildQueryString(NameValueCollection parameters) public static string BuildQueryString(NameValueCollection parameters)
{ {
List<string> items = new List<string>(parameters.Count); if (parameters.Count == 0)
return string.Empty;
StringBuilder sb = new StringBuilder(4096);
foreach (string key in parameters.Keys) foreach (string key in parameters.Keys)
{ {
string[] values = parameters.GetValues(key); string[] values = parameters.GetValues(key);
if (values != null) if (values != null)
{ {
foreach (string value in values) foreach (string value in values)
items.Add(String.Concat(key, "=", HttpUtility.UrlEncode(value ?? String.Empty))); {
sb.Append(key);
sb.Append("=");
if(!string.IsNullOrWhiteSpace(value))
sb.Append(HttpUtility.UrlEncode(value));
sb.Append("&");
}
} }
} }
return String.Join("&", items.ToArray()); if(sb.Length > 1)
sb.Length--;
return sb.ToString();
} }
/// <summary> /// <summary>
@ -1097,9 +1108,7 @@ namespace OpenSim.Framework
public class SynchronousRestObjectRequester public class SynchronousRestObjectRequester
{ {
private static readonly ILog m_log = private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
/// <summary> /// <summary>
/// Perform a synchronous REST request. /// Perform a synchronous REST request.

View File

@ -94,7 +94,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return layer; return layer;
} }
public static void CreatePatchtStandardSize(BitPack output, float[] patchData, int x, int y) public unsafe static void CreatePatchtStandardSize(BitPack output, float[] patchData, int x, int y)
{ {
TerrainPatch.Header header = PrescanPatch(patchData); TerrainPatch.Header header = PrescanPatch(patchData);
header.QuantWBits = 136; header.QuantWBits = 136;
@ -103,7 +103,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
header.PatchIDs += (x << 5); header.PatchIDs += (x << 5);
int wbits; int wbits;
int[] patch = CompressPatch(patchData, header, 10, out wbits); int* patch = stackalloc int[256];
CompressPatch(patchData, header, 10, out wbits, patch);
EncodePatchHeader(output, header, false, ref wbits); EncodePatchHeader(output, header, false, ref wbits);
EncodePatch(output, patch, 0, wbits); EncodePatch(output, patch, 0, wbits);
} }
@ -127,9 +128,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return header; return header;
} }
private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits) private unsafe static void CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits, int* iout)
{ {
float[] block = new float[256]; float* block = stackalloc float[256];
float oozrange = 1.0f / header.Range; float oozrange = 1.0f / header.Range;
float range = (1 << prequant); float range = (1 << prequant);
float premult = oozrange * range; float premult = oozrange * range;
@ -148,11 +149,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
wbits = (prequant >> 1); wbits = (prequant >> 1);
int[] iout = new int[256];
dct16x16(block, iout, ref wbits); dct16x16(block, iout, ref wbits);
return iout;
} }
/* /*
@ -216,7 +214,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
*/ */
public static void CreatePatchFromTerrainData(BitPack output, TerrainData terrData, int patchX, int patchY) public unsafe static void CreatePatchFromTerrainData(BitPack output, TerrainData terrData, int patchX, int patchY)
{ {
float frange; float frange;
@ -255,7 +253,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
int wbits; int wbits;
int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits); int* patch = stackalloc int[256];
CompressPatch(terrData, patchX, patchY, header, 10, out wbits, patch);
EncodePatchHeader(output, header, largeRegion, ref wbits); EncodePatchHeader(output, header, largeRegion, ref wbits);
EncodePatch(output, patch, 0, wbits); EncodePatch(output, patch, 0, wbits);
} }
@ -295,7 +294,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
output.PackBits(header.PatchIDs, 10); output.PackBits(header.PatchIDs, 10);
} }
private unsafe static void EncodePatch(BitPack output, int[] _patch, int postquant, int wbits) private unsafe static void EncodePatch(BitPack output, int* patch, int postquant, int wbits)
{ {
int maxwbitssize = (1 << wbits) - 1; int maxwbitssize = (1 << wbits) - 1;
@ -307,71 +306,67 @@ namespace OpenSim.Region.ClientStack.LindenUDP
int lastZeroindx = 256 - postquant; int lastZeroindx = 256 - postquant;
fixed(int * patch = _patch) if (lastZeroindx != 256)
patch[lastZeroindx] = 0;
int i = 0;
while(i < 256)
{ {
if (lastZeroindx != 256) int temp = patch[i];
patch[lastZeroindx] = 0;
int i = 0; if (temp == 0)
while(i < 256)
{ {
int temp = patch[i]; int j = i + 1;
while(j < lastZeroindx)
if (temp == 0)
{ {
int j = i + 1; if (patch[j] != 0)
while(j < lastZeroindx) break;
{ ++j;
if (patch[j] != 0)
break;
++j;
}
if (j == lastZeroindx)
{
output.PackBits(ZERO_EOB, 2);
return;
}
i = j - i;
while(i > 8)
{
output.PackBitsFromByte(ZERO_CODE);
i -= 8;
}
if( i > 0)
output.PackBitsFromByte(ZERO_CODE, i);
i = j;
continue;
} }
if (temp < 0) if (j == lastZeroindx)
{ {
temp *= -1; output.PackBits(ZERO_EOB, 2);
if (temp > maxwbitssize) return;
temp = maxwbitssize;
output.PackBits(NEGATIVE_VALUE, 3);
output.PackBits(temp, wbits);
} }
else
i = j - i;
while(i > 8)
{ {
if (temp > maxwbitssize) output.PackBitsFromByte(ZERO_CODE);
temp = maxwbitssize; i -= 8;
output.PackBits(POSITIVE_VALUE, 3);
output.PackBits(temp, wbits);
} }
++i; if( i > 0)
output.PackBitsFromByte(ZERO_CODE, i);
i = j;
continue;
} }
if (temp < 0)
{
temp *= -1;
if (temp > maxwbitssize)
temp = maxwbitssize;
output.PackBits(NEGATIVE_VALUE, 3);
output.PackBits(temp, wbits);
}
else
{
if (temp > maxwbitssize)
temp = maxwbitssize;
output.PackBits(POSITIVE_VALUE, 3);
output.PackBits(temp, wbits);
}
++i;
} }
} }
private static int[] CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header, private unsafe static void CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header,
int prequant, out int wbits) int prequant, out int wbits, int* iout)
{ {
float[] block = new float[256]; float* block = stackalloc float[256];
int[] iout = new int[256];
float oozrange = 1.0f / header.Range; float oozrange = 1.0f / header.Range;
float invprequat = (1 << prequant); float invprequat = (1 << prequant);
@ -388,7 +383,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
wbits = (prequant >> 1); wbits = (prequant >> 1);
dct16x16(block, iout, ref wbits); dct16x16(block, iout, ref wbits);
return iout;
} }
#region Initialization #region Initialization
@ -523,9 +517,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
const float W16_8R = 0.70710678118654752440f; const float W16_8R = 0.70710678118654752440f;
unsafe static void dct16x16(float[] _a, int[] _iout, ref int wbits) unsafe static void dct16x16(float* a, int* iout, ref int wbits)
{ {
float[] _tmp = new float[256]; float* tmp = stackalloc float[256];
float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
float x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i; float x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i;
@ -540,8 +534,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
int wbitsMaxValue = 1 << wbits; int wbitsMaxValue = 1 << wbits;
bool dowbits = wbits < 17; bool dowbits = wbits < 17;
fixed (float* a = _a, tmp = _tmp, fQuantizeTable16 = QuantizeTable16) fixed (float* fQuantizeTable16 = QuantizeTable16)
fixed (int* iout = _iout, fCopyMatrix16 = CopyMatrix16) fixed (int* fCopyMatrix16 = CopyMatrix16)
{ {
for (j = 0, k = 0; j < 256; j += 16, k++) for (j = 0, k = 0; j < 256; j += 16, k++)
{ {