Changeset 59745 in vbox
- Timestamp:
- Feb 19, 2016 9:54:11 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/sg.h
r56291 r59745 149 149 * @param pSgBuf2 Second S/G buffer. 150 150 * @param cbCmp How many bytes to compare. 151 * @param p cbOffWhere to store the offset of the first different byte151 * @param poffDiff Where to store the offset of the first different byte 152 152 * in the buffer starting from the position of the S/G 153 153 * buffer before this call. -
trunk/src/VBox/Runtime/common/misc/sg.cpp
r58334 r59745 35 35 36 36 37 static void * sgBufGet(PRTSGBUF pSgBuf, size_t *pcbData)37 static void *rtSgBufGet(PRTSGBUF pSgBuf, size_t *pcbData) 38 38 { 39 39 size_t cbData; … … 127 127 *pcbSeg = pSgBuf->cbSegLeft; 128 128 129 return sgBufGet(pSgBuf, pcbSeg);129 return rtSgBufGet(pSgBuf, pcbSeg); 130 130 } 131 131 … … 137 137 138 138 size_t cbLeft = cbCopy; 139 140 139 while (cbLeft) 141 140 { 142 141 size_t cbThisCopy = RT_MIN(RT_MIN(pSgBufDst->cbSegLeft, cbLeft), pSgBufSrc->cbSegLeft); 142 if (!cbThisCopy) 143 break; 144 143 145 size_t cbTmp = cbThisCopy; 144 void *pvBufDst; 145 void *pvBufSrc; 146 147 if (!cbThisCopy) 148 break; 149 150 pvBufDst = sgBufGet(pSgBufDst, &cbTmp); 146 void *pvBufDst = rtSgBufGet(pSgBufDst, &cbTmp); 151 147 Assert(cbTmp == cbThisCopy); 152 pvBufSrc = sgBufGet(pSgBufSrc, &cbTmp);148 void *pvBufSrc = rtSgBufGet(pSgBufSrc, &cbTmp); 153 149 Assert(cbTmp == cbThisCopy); 154 150 … … 167 163 AssertPtrReturn(pSgBuf2, 0); 168 164 165 /* Set up the temporary buffers */ 166 RTSGBUF SgBuf1; 167 RTSgBufClone(&SgBuf1, pSgBuf1); 168 RTSGBUF SgBuf2; 169 RTSgBufClone(&SgBuf2, pSgBuf2); 170 169 171 size_t cbLeft = cbCmp; 170 RTSGBUF SgBuf1;171 RTSGBUF SgBuf2;172 173 /* Set up the temporary buffers */174 RTSgBufClone(&SgBuf1, pSgBuf1);175 RTSgBufClone(&SgBuf2, pSgBuf2);176 177 172 while (cbLeft) 178 173 { 179 174 size_t cbThisCmp = RT_MIN(RT_MIN(SgBuf1.cbSegLeft, cbLeft), SgBuf2.cbSegLeft); 175 if (!cbThisCmp) 176 break; 177 180 178 size_t cbTmp = cbThisCmp; 181 void *pvBuf1; 182 void *pvBuf2; 183 184 if (!cbCmp) 185 break; 186 187 pvBuf1 = sgBufGet(&SgBuf1, &cbTmp); 179 void *pvBuf1 = rtSgBufGet(&SgBuf1, &cbTmp); 188 180 Assert(cbTmp == cbThisCmp); 189 pvBuf2 = sgBufGet(&SgBuf2, &cbTmp);181 void *pvBuf2 = rtSgBufGet(&SgBuf2, &cbTmp); 190 182 Assert(cbTmp == cbThisCmp); 191 183 … … 201 193 202 194 203 RTDECL(int) RTSgBufCmpEx(PRTSGBUF pSgBuf1, PRTSGBUF pSgBuf2, size_t cbCmp, 204 size_t *pcbOff, bool fAdvance) 195 RTDECL(int) RTSgBufCmpEx(PRTSGBUF pSgBuf1, PRTSGBUF pSgBuf2, size_t cbCmp, size_t *poffDiff, bool fAdvance) 205 196 { 206 197 AssertPtrReturn(pSgBuf1, 0); 207 198 AssertPtrReturn(pSgBuf2, 0); 208 199 209 size_t cbLeft = cbCmp;210 size_t cbOff = 0;211 200 RTSGBUF SgBuf1Tmp; 212 201 RTSGBUF SgBuf2Tmp; … … 228 217 } 229 218 219 size_t cbLeft = cbCmp; 220 size_t off = 0; 230 221 while (cbLeft) 231 222 { 232 223 size_t cbThisCmp = RT_MIN(RT_MIN(pSgBuf1Tmp->cbSegLeft, cbLeft), pSgBuf2Tmp->cbSegLeft); 224 if (!cbThisCmp) 225 break; 226 233 227 size_t cbTmp = cbThisCmp; 234 uint8_t *pbBuf1; 235 uint8_t *pbBuf2; 236 237 if (!cbCmp) 238 break; 239 240 pbBuf1 = (uint8_t *)sgBufGet(pSgBuf1Tmp, &cbTmp); 228 uint8_t *pbBuf1 = (uint8_t *)rtSgBufGet(pSgBuf1Tmp, &cbTmp); 241 229 Assert(cbTmp == cbThisCmp); 242 pbBuf2 = (uint8_t *)sgBufGet(pSgBuf2Tmp, &cbTmp);230 uint8_t *pbBuf2 = (uint8_t *)rtSgBufGet(pSgBuf2Tmp, &cbTmp); 243 231 Assert(cbTmp == cbThisCmp); 244 232 245 int rc = memcmp(pbBuf1, pbBuf2, cbThisCmp); 246 if (rc) 247 { 248 if (pcbOff) 233 int iDiff = memcmp(pbBuf1, pbBuf2, cbThisCmp); 234 if (iDiff) 235 { 236 /* Locate the first byte that differs if the caller requested this. */ 237 if (poffDiff) 249 238 { 250 /* Search for the correct offset */251 239 while ( cbThisCmp-- > 0 252 && (*pbBuf1 == *pbBuf2))240 && *pbBuf1 == *pbBuf2) 253 241 { 254 242 pbBuf1++; 255 243 pbBuf2++; 256 cbOff++;244 off++; 257 245 } 258 246 259 *p cbOff = cbOff;247 *poffDiff = off; 260 248 } 261 return rc;249 return iDiff; 262 250 } 263 251 264 252 cbLeft -= cbThisCmp; 265 cbOff+= cbThisCmp;253 off += cbThisCmp; 266 254 } 267 255 … … 279 267 { 280 268 size_t cbThisSet = cbLeft; 281 void *pvBuf = sgBufGet(pSgBuf, &cbThisSet);269 void *pvBuf = rtSgBufGet(pSgBuf, &cbThisSet); 282 270 283 271 if (!cbThisSet) … … 303 291 { 304 292 size_t cbThisCopy = cbLeft; 305 void *pvSrc = sgBufGet(pSgBuf, &cbThisCopy);293 void *pvSrc = rtSgBufGet(pSgBuf, &cbThisCopy); 306 294 307 295 if (!cbThisCopy) … … 328 316 { 329 317 size_t cbThisCopy = cbLeft; 330 void *pvDst = sgBufGet(pSgBuf, &cbThisCopy);318 void *pvDst = rtSgBufGet(pSgBuf, &cbThisCopy); 331 319 332 320 if (!cbThisCopy) … … 348 336 349 337 size_t cbLeft = cbAdvance; 350 351 338 while (cbLeft) 352 339 { 353 340 size_t cbThisAdvance = cbLeft; 354 void *pv = sgBufGet(pSgBuf, &cbThisAdvance); 355 356 NOREF(pv); 357 341 rtSgBufGet(pSgBuf, &cbThisAdvance); 358 342 if (!cbThisAdvance) 359 343 break; … … 400 384 { 401 385 size_t cbThisSeg = cbData; 402 void *pvSeg = NULL; 403 404 pvSeg = sgBufGet(pSgBuf, &cbThisSeg); 386 void *pvSeg = rtSgBufGet(pSgBuf, &cbThisSeg); 405 387 406 388 if (!cbThisSeg) … … 427 409 RTDECL(bool) RTSgBufIsZero(PRTSGBUF pSgBuf, size_t cbCheck) 428 410 { 429 bool fIsZero = true;430 size_t cbLeft = cbCheck;431 411 RTSGBUF SgBufTmp; 432 433 412 RTSgBufClone(&SgBufTmp, pSgBuf); 434 413 414 bool fIsZero = true; 415 size_t cbLeft = cbCheck; 435 416 while (cbLeft) 436 417 { 437 418 size_t cbThisCheck = cbLeft; 438 void *pvBuf = sgBufGet(&SgBufTmp, &cbThisCheck); 439 419 void *pvBuf = rtSgBufGet(&SgBufTmp, &cbThisCheck); 440 420 if (!cbThisCheck) 441 421 break; 442 422 423 /** @todo fix this after asm.h gets updated. */ 443 424 /* Use optimized inline assembler if possible. */ 444 425 if ( !(cbThisCheck % 4) 445 && (cbThisCheck * 8 <= UINT32_MAX))426 && cbThisCheck * 8 <= UINT32_MAX) 446 427 { 447 428 if (ASMBitFirstSet((volatile void *)pvBuf, (uint32_t)cbThisCheck * 8) != -1) … … 453 434 else 454 435 { 455 for ( unsignedi = 0; i < cbThisCheck; i++)436 for (size_t i = 0; i < cbThisCheck; i++) 456 437 { 457 438 char *pbBuf = (char *)pvBuf;
Note:
See TracChangeset
for help on using the changeset viewer.