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

Side by Side Diff: third_party/WebKit/Source/core/dom/NodeWithIndex.h

Issue 2701413003: Range: node offsets should be unsigned. (Closed)
Patch Set: Resolve std::numeric_limits<int>::max() leftover Created 3 years, 10 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 // For use when you want to get the index for a node repeatedly and 34 // For use when you want to get the index for a node repeatedly and
35 // only want to walk the child list to figure out the index once. 35 // only want to walk the child list to figure out the index once.
36 class NodeWithIndex { 36 class NodeWithIndex {
37 STACK_ALLOCATED(); 37 STACK_ALLOCATED();
38 38
39 public: 39 public:
40 explicit NodeWithIndex(Node& node) : m_node(node), m_index(-1) {} 40 explicit NodeWithIndex(Node& node) : m_node(node), m_index(-1) {}
41 41
42 Node& node() const { return *m_node; } 42 Node& node() const { return *m_node; }
43 43
44 // TODO(tkent): Should be unsigned.
44 int index() const { 45 int index() const {
45 if (!hasIndex()) 46 if (!hasIndex())
46 m_index = node().nodeIndex(); 47 m_index = node().nodeIndex();
47 DCHECK(hasIndex()); 48 DCHECK(hasIndex());
48 DCHECK_EQ(m_index, static_cast<int>(node().nodeIndex())); 49 DCHECK_EQ(m_index, static_cast<int>(node().nodeIndex()));
49 return m_index; 50 return m_index;
50 } 51 }
51 52
52 private: 53 private:
53 bool hasIndex() const { return m_index >= 0; } 54 bool hasIndex() const { return m_index >= 0; }
54 55
55 Member<Node> m_node; 56 Member<Node> m_node;
56 mutable int m_index; 57 mutable int m_index;
57 }; 58 };
58 59
59 } // namespace blink 60 } // namespace blink
60 61
61 #endif 62 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698