mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-29 11:26:17 +03:00
Reduced memory usage
This commit is contained in:
parent
6541bd7cb5
commit
6764650e2a
|
@ -803,37 +803,35 @@ build_distance_tables(
|
||||||
uint32_t i, j;
|
uint32_t i, j;
|
||||||
DistanceWithIndex *dwi;
|
DistanceWithIndex *dwi;
|
||||||
|
|
||||||
dwi = calloc(nEntries * nEntries, sizeof(DistanceWithIndex));
|
for (i = 0; i < nEntries; i++) {
|
||||||
|
avgDist[i * nEntries + i] = 0;
|
||||||
|
avgDistSortKey[i * nEntries + i] = &(avgDist[i * nEntries + i]);
|
||||||
|
for (j = 0; j < i; j++) {
|
||||||
|
avgDist[j * nEntries + i] = avgDist[i * nEntries + j] =
|
||||||
|
_DISTSQR(p + i, p + j);
|
||||||
|
avgDistSortKey[j * nEntries + i] = &(avgDist[j * nEntries + i]);
|
||||||
|
avgDistSortKey[i * nEntries + j] = &(avgDist[i * nEntries + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dwi = calloc(nEntries, sizeof(DistanceWithIndex));
|
||||||
if (!dwi) {
|
if (!dwi) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (i = 0; i < nEntries; i++) {
|
for (i = 0; i < nEntries; i++) {
|
||||||
avgDist[i * nEntries + i] = 0;
|
for (j = 0; j < nEntries; j++) {
|
||||||
dwi[i * nEntries + i] = (DistanceWithIndex){
|
dwi[j] = (DistanceWithIndex){
|
||||||
&(avgDist[i * nEntries + i]),
|
|
||||||
i * nEntries + i
|
|
||||||
};
|
|
||||||
for (j = 0; j < i; j++) {
|
|
||||||
avgDist[j * nEntries + i] = avgDist[i * nEntries + j] =
|
|
||||||
_DISTSQR(p + i, p + j);
|
|
||||||
dwi[j * nEntries + i] = (DistanceWithIndex){
|
|
||||||
&(avgDist[j * nEntries + i]),
|
|
||||||
j * nEntries + i
|
|
||||||
};
|
|
||||||
dwi[i * nEntries + j] = (DistanceWithIndex){
|
|
||||||
&(avgDist[i * nEntries + j]),
|
&(avgDist[i * nEntries + j]),
|
||||||
i * nEntries + j
|
j
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (i = 0; i < nEntries; i++) {
|
|
||||||
qsort(
|
qsort(
|
||||||
dwi + i * nEntries,
|
dwi,
|
||||||
nEntries,
|
nEntries,
|
||||||
sizeof(DistanceWithIndex),
|
sizeof(DistanceWithIndex),
|
||||||
_sort_ulong_ptr_keys);
|
_sort_ulong_ptr_keys);
|
||||||
for (j = 0; j < nEntries; j++) {
|
for (j = 0; j < nEntries; j++) {
|
||||||
avgDistSortKey[i * nEntries + j] = dwi[i * nEntries + j].distance;
|
avgDistSortKey[i * nEntries + j] = dwi[j].distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(dwi);
|
free(dwi);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user