Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: Source/core/fetch/MemoryCache.cpp

Issue 660723002: MemoryCache: Remove ENABLE(ASSERT) checks for readability (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 { 397 {
398 ASSERT(accessCount > 0); 398 ASSERT(accessCount > 0);
399 unsigned queueIndex = WTF::fastLog2(size / accessCount); 399 unsigned queueIndex = WTF::fastLog2(size / accessCount);
400 if (m_allResources.size() <= queueIndex) 400 if (m_allResources.size() <= queueIndex)
401 m_allResources.grow(queueIndex + 1); 401 m_allResources.grow(queueIndex + 1);
402 return &m_allResources[queueIndex]; 402 return &m_allResources[queueIndex];
403 } 403 }
404 404
405 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list) 405 void MemoryCache::removeFromLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list)
406 { 406 {
407 #if ENABLE(ASSERT) 407 ASSERT(containsInLRUList(entry, list));
Mike West 2014/10/16 06:34:46 This is a huge improvement, thank you.
408 // Verify that we are in fact in this list.
409 bool found = false;
410 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) {
411 if (current == entry) {
412 found = true;
413 break;
414 }
415 }
416 ASSERT(found);
417 #endif
418 408
419 MemoryCacheEntry* next = entry->m_nextInAllResourcesList; 409 MemoryCacheEntry* next = entry->m_nextInAllResourcesList;
420 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList; 410 MemoryCacheEntry* previous = entry->m_previousInAllResourcesList;
421 entry->m_nextInAllResourcesList = nullptr; 411 entry->m_nextInAllResourcesList = nullptr;
422 entry->m_previousInAllResourcesList = nullptr; 412 entry->m_previousInAllResourcesList = nullptr;
423 413
424 if (next) 414 if (next)
425 next->m_previousInAllResourcesList = previous; 415 next->m_previousInAllResourcesList = previous;
426 else 416 else
427 list->m_tail = previous; 417 list->m_tail = previous;
428 418
429 if (previous) 419 if (previous)
430 previous->m_nextInAllResourcesList = next; 420 previous->m_nextInAllResourcesList = next;
431 else 421 else
432 list->m_head = next; 422 list->m_head = next;
423
424 ASSERT(!containsInLRUList(entry, list));
433 } 425 }
434 426
435 void MemoryCache::insertInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* l ist) 427 void MemoryCache::insertInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* l ist)
436 { 428 {
437 ASSERT(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist); 429 ASSERT(!containsInLRUList(entry, list));
438 430
439 entry->m_nextInAllResourcesList = list->m_head; 431 entry->m_nextInAllResourcesList = list->m_head;
440 list->m_head = entry; 432 list->m_head = entry;
441 433
442 if (entry->m_nextInAllResourcesList) 434 if (entry->m_nextInAllResourcesList)
443 entry->m_nextInAllResourcesList->m_previousInAllResourcesList = entry; 435 entry->m_nextInAllResourcesList->m_previousInAllResourcesList = entry;
444 else 436 else
445 list->m_tail = entry; 437 list->m_tail = entry;
446 438
447 #if ENABLE(ASSERT) 439 ASSERT(containsInLRUList(entry, list));
448 // Verify that we are in now in the list like we should be. 440 }
449 bool found = false; 441
442 bool MemoryCache::containsInLRUList(MemoryCacheEntry* entry, MemoryCacheLRUList* list)
443 {
450 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) { 444 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInAllResourcesList) {
451 if (current == entry) { 445 if (current == entry)
452 found = true; 446 return true;
453 break;
454 }
455 } 447 }
456 ASSERT(found); 448 ASSERT(!entry->m_nextInAllResourcesList && !entry->m_previousInAllResourcesL ist);
457 #endif 449 return false;
458 } 450 }
459 451
460 void MemoryCache::removeFromLiveDecodedResourcesList(MemoryCacheEntry* entry) 452 void MemoryCache::removeFromLiveDecodedResourcesList(MemoryCacheEntry* entry)
461 { 453 {
462 // If we've never been accessed, then we're brand new and not in any list. 454 // If we've never been accessed, then we're brand new and not in any list.
463 if (!entry->m_inLiveDecodedResourcesList) 455 if (!entry->m_inLiveDecodedResourcesList)
464 return; 456 return;
457 ASSERT(containsInLiveDecodedResourcesList(entry));
458
465 entry->m_inLiveDecodedResourcesList = false; 459 entry->m_inLiveDecodedResourcesList = false;
466 460
467 MemoryCacheLRUList* list = &m_liveDecodedResources[entry->m_liveResourcePrio rity]; 461 MemoryCacheLRUList* list = &m_liveDecodedResources[entry->m_liveResourcePrio rity];
468 462
469 #if ENABLE(ASSERT)
470 // Verify that we are in fact in this list.
471 bool found = false;
472 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInLiveResourcesList) {
473 if (current == entry) {
474 found = true;
475 break;
476 }
477 }
478 ASSERT(found);
479 #endif
480
481 MemoryCacheEntry* next = entry->m_nextInLiveResourcesList; 463 MemoryCacheEntry* next = entry->m_nextInLiveResourcesList;
482 MemoryCacheEntry* previous = entry->m_previousInLiveResourcesList; 464 MemoryCacheEntry* previous = entry->m_previousInLiveResourcesList;
483 465
484 entry->m_nextInLiveResourcesList = nullptr; 466 entry->m_nextInLiveResourcesList = nullptr;
485 entry->m_previousInLiveResourcesList = nullptr; 467 entry->m_previousInLiveResourcesList = nullptr;
486 468
487 if (next) 469 if (next)
488 next->m_previousInLiveResourcesList = previous; 470 next->m_previousInLiveResourcesList = previous;
489 else 471 else
490 list->m_tail = previous; 472 list->m_tail = previous;
491 473
492 if (previous) 474 if (previous)
493 previous->m_nextInLiveResourcesList = next; 475 previous->m_nextInLiveResourcesList = next;
494 else 476 else
495 list->m_head = next; 477 list->m_head = next;
478
479 ASSERT(!containsInLiveDecodedResourcesList(entry));
496 } 480 }
497 481
498 void MemoryCache::insertInLiveDecodedResourcesList(MemoryCacheEntry* entry) 482 void MemoryCache::insertInLiveDecodedResourcesList(MemoryCacheEntry* entry)
499 { 483 {
500 // Make sure we aren't in the list already. 484 ASSERT(!containsInLiveDecodedResourcesList(entry));
501 ASSERT(!entry->m_nextInLiveResourcesList && !entry->m_previousInLiveResource sList && !entry->m_inLiveDecodedResourcesList); 485
502 entry->m_inLiveDecodedResourcesList = true; 486 entry->m_inLiveDecodedResourcesList = true;
503 487
504 MemoryCacheLRUList* list = &m_liveDecodedResources[entry->m_liveResourcePrio rity]; 488 MemoryCacheLRUList* list = &m_liveDecodedResources[entry->m_liveResourcePrio rity];
505 entry->m_nextInLiveResourcesList = list->m_head; 489 entry->m_nextInLiveResourcesList = list->m_head;
506 if (list->m_head) 490 if (list->m_head)
507 list->m_head->m_previousInLiveResourcesList = entry; 491 list->m_head->m_previousInLiveResourcesList = entry;
508 list->m_head = entry; 492 list->m_head = entry;
509 493
510 if (!entry->m_nextInLiveResourcesList) 494 if (!entry->m_nextInLiveResourcesList)
511 list->m_tail = entry; 495 list->m_tail = entry;
512 496
513 #if ENABLE(ASSERT) 497 ASSERT(containsInLiveDecodedResourcesList(entry));
514 // Verify that we are in now in the list like we should be. 498 }
515 bool found = false; 499
500 bool MemoryCache::containsInLiveDecodedResourcesList(MemoryCacheEntry* entry)
501 {
502 MemoryCacheLRUList* list = &m_liveDecodedResources[entry->m_liveResourcePrio rity];
516 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInLiveResourcesList) { 503 for (MemoryCacheEntry* current = list->m_head; current; current = current->m _nextInLiveResourcesList) {
517 if (current == entry) { 504 if (current == entry) {
518 found = true; 505 ASSERT(entry->m_inLiveDecodedResourcesList);
519 break; 506 return true;
520 } 507 }
521 } 508 }
522 ASSERT(found); 509 ASSERT(!entry->m_nextInLiveResourcesList && !entry->m_previousInLiveResource sList && !entry->m_inLiveDecodedResourcesList);
523 #endif 510 return false;
524 } 511 }
525 512
526 void MemoryCache::makeLive(Resource* resource) 513 void MemoryCache::makeLive(Resource* resource)
527 { 514 {
528 if (!contains(resource)) 515 if (!contains(resource))
529 return; 516 return;
530 ASSERT(m_deadSize >= resource->size()); 517 ASSERT(m_deadSize >= resource->size());
531 m_liveSize += resource->size(); 518 m_liveSize += resource->size();
532 m_deadSize -= resource->size(); 519 m_deadSize -= resource->size();
533 } 520 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSiz e() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, cur rent->accessCount(), current->hasClients(), current->isPurgeable(), current->was Purged()); 789 printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSiz e() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, cur rent->accessCount(), current->hasClients(), current->isPurgeable(), current->was Purged());
803 790
804 current = prev; 791 current = prev;
805 } 792 }
806 } 793 }
807 } 794 }
808 795
809 #endif // MEMORY_CACHE_STATS 796 #endif // MEMORY_CACHE_STATS
810 797
811 } // namespace blink 798 } // namespace blink
OLDNEW
« Source/core/fetch/MemoryCache.h ('K') | « Source/core/fetch/MemoryCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698