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

Side by Side Diff: ui/base/sequential_id_generator.cc

Issue 23654045: ui: Fix removing a number from the SequentialIDGenerator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/base/sequential_id_generator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/sequential_id_generator.h" 5 #include "ui/base/sequential_id_generator.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 void SequentialIDGenerator::ReleaseGeneratedID(uint32 id) { 53 void SequentialIDGenerator::ReleaseGeneratedID(uint32 id) {
54 if (id < min_available_id_) { 54 if (id < min_available_id_) {
55 min_available_id_ = id; 55 min_available_id_ = id;
56 DCHECK_GE(min_available_id_, min_id_); 56 DCHECK_GE(min_available_id_, min_id_);
57 } 57 }
58 Remove(id, &id_to_number_, &number_to_id_); 58 Remove(id, &id_to_number_, &number_to_id_);
59 } 59 }
60 60
61 void SequentialIDGenerator::ReleaseNumber(uint32 number) { 61 void SequentialIDGenerator::ReleaseNumber(uint32 number) {
62 DCHECK_GT(number_to_id_.count(number), 0U);
63 uint32 id = number_to_id_[number];
64 if (id < min_available_id_) {
sky 2013/09/16 23:49:27 Refactor 54-57 and 64-67 to a common method?
sadrul 2013/09/17 02:26:38 Done.
65 min_available_id_ = id;
66 DCHECK_GE(min_available_id_, min_id_);
67 }
62 Remove(number, &number_to_id_, &id_to_number_); 68 Remove(number, &number_to_id_, &id_to_number_);
63 } 69 }
64 70
65 uint32 SequentialIDGenerator::GetNextAvailableSlot() { 71 uint32 SequentialIDGenerator::GetNextAvailableSlot() {
66 const uint32 kMaxID = 128; 72 const uint32 kMaxID = 128;
67 while (id_to_number_.count(min_available_id_) > 0 && 73 while (id_to_number_.count(min_available_id_) > 0 &&
68 min_available_id_ < kMaxID) { 74 min_available_id_ < kMaxID) {
69 ++min_available_id_; 75 ++min_available_id_;
70 } 76 }
71 if (min_available_id_ >= kMaxID) 77 if (min_available_id_ >= kMaxID)
72 min_available_id_ = min_id_; 78 min_available_id_ = min_id_;
73 return min_available_id_; 79 return min_available_id_;
74 } 80 }
75 81
76 } // namespace ui 82 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/base/sequential_id_generator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698