OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This file contains the implementation of IdAllocator. | 5 // This file contains the implementation of IdAllocator. |
6 | 6 |
7 #include "../common/id_allocator.h" | 7 #include "../common/id_allocator.h" |
8 #include "../common/logging.h" | 8 #include "../common/logging.h" |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
11 | 11 |
12 IdAllocator::IdAllocator() { | 12 IdAllocator::IdAllocator() { |
13 } | 13 } |
14 | 14 |
15 ResourceId IdAllocator::FindFirstFree() const { | 15 ResourceId IdAllocator::FindFirstFree() const { |
16 ResourceId id = 1; | 16 ResourceId id = 1; |
17 for (ResourceIdSet::const_iterator it = used_ids_.begin(); | 17 for (ResourceIdSet::const_iterator it = used_ids_.begin(); |
18 it != used_ids_.end(); ++it) { | 18 it != used_ids_.end(); ++it) { |
19 if ((*it) != id) { | 19 if ((*it) != id) { |
20 return id; | 20 return id; |
21 } | 21 } |
22 ++id; | 22 ++id; |
23 } | 23 } |
24 return id; | 24 return id; |
25 } | 25 } |
26 | 26 |
27 ResourceId IdAllocator::AllocateIDAtOrAbove(ResourceId desired_id) { | 27 ResourceId IdAllocator::AllocateIDAtOrAbove(ResourceId desired_id) { |
28 DCHECK_LT(static_cast<ResourceId>(used_ids_.size()), | 28 DCHECK_LT(static_cast<ResourceId>(used_ids_.size()), |
29 static_cast<ResourceId>(-1)); | 29 static_cast<ResourceId>(-1)); |
30 for (; InUse(desired_id); ++desired_id); | 30 for (; InUse(desired_id); ++desired_id) {} |
31 MarkAsUsed(desired_id); | 31 MarkAsUsed(desired_id); |
32 return desired_id; | 32 return desired_id; |
33 } | 33 } |
34 | 34 |
35 } // namespace gpu | 35 } // namespace gpu |
OLD | NEW |