diff options
author | nyamatongwe <unknown> | 2013-05-03 16:22:14 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2013-05-03 16:22:14 +1000 |
commit | 807ba474304f0fdeed7548518f5c4f22517be82b (patch) | |
tree | 231a6df69801287a220e43e5fe864c73160697f4 | |
parent | e4cfb287a2b9f8a283f5347a262efd95c88014d1 (diff) | |
download | scintilla-mirror-807ba474304f0fdeed7548518f5c4f22517be82b.tar.gz |
Replacing raw pointers and allocations with std::vector.
-rw-r--r-- | src/KeyMap.cxx | 34 | ||||
-rw-r--r-- | src/KeyMap.h | 4 |
2 files changed, 14 insertions, 24 deletions
diff --git a/src/KeyMap.cxx b/src/KeyMap.cxx index 4d866d195..ab8be2f9e 100644 --- a/src/KeyMap.cxx +++ b/src/KeyMap.cxx @@ -5,6 +5,10 @@ // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org> // The License.txt file describes the conditions under which this software may be distributed. +#include <stdlib.h> + +#include <vector> + #include "Platform.h" #include "Scintilla.h" @@ -15,7 +19,7 @@ using namespace Scintilla; #endif -KeyMap::KeyMap() : kmap(0), len(0), alloc(0) { +KeyMap::KeyMap() { for (int i = 0; MapDefault[i].key; i++) { AssignCmdKey(MapDefault[i].key, MapDefault[i].modifiers, @@ -28,37 +32,25 @@ KeyMap::~KeyMap() { } void KeyMap::Clear() { - delete []kmap; - kmap = 0; - len = 0; - alloc = 0; + kmap.clear(); } void KeyMap::AssignCmdKey(int key, int modifiers, unsigned int msg) { - if ((len+1) >= alloc) { - KeyToCommand *ktcNew = new KeyToCommand[alloc + 5]; - if (!ktcNew) - return; - for (int k = 0; k < len; k++) - ktcNew[k] = kmap[k]; - alloc += 5; - delete []kmap; - kmap = ktcNew; - } - for (int keyIndex = 0; keyIndex < len; keyIndex++) { + for (size_t keyIndex = 0; keyIndex < kmap.size(); keyIndex++) { if ((key == kmap[keyIndex].key) && (modifiers == kmap[keyIndex].modifiers)) { kmap[keyIndex].msg = msg; return; } } - kmap[len].key = key; - kmap[len].modifiers = modifiers; - kmap[len].msg = msg; - len++; + KeyToCommand ktc; + ktc.key = key; + ktc.modifiers = modifiers; + ktc.msg = msg; + kmap.push_back(ktc); } unsigned int KeyMap::Find(int key, int modifiers) { - for (int i = 0; i < len; i++) { + for (size_t i = 0; i < kmap.size(); i++) { if ((key == kmap[i].key) && (modifiers == kmap[i].modifiers)) { return kmap[i].msg; } diff --git a/src/KeyMap.h b/src/KeyMap.h index f1235d845..ee4d29ce2 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -32,9 +32,7 @@ public: /** */ class KeyMap { - KeyToCommand *kmap; - int len; - int alloc; + std::vector<KeyToCommand> kmap; static const KeyToCommand MapDefault[]; public: |