1.1 --- a/src/StringPool.cpp Mon Jun 10 00:46:29 2013 +0100
1.2 +++ b/src/StringPool.cpp Mon Jun 10 01:04:43 2013 +0100
1.3 @@ -1,72 +1,72 @@
1.4 -/*
1.5 - * Copyright (C) 2012 David Anderson
1.6 - *
1.7 - * This file is part of JITCraft.
1.8 - *
1.9 - * JITCraft is free software: you can redistribute it and/or modify it under
1.10 - * the terms of the GNU General Public License as published by the Free
1.11 - * Software Foundation, either version 3 of the License, or (at your option)
1.12 - * any later version.
1.13 - *
1.14 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.15 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.17 - *
1.18 - * You should have received a copy of the GNU General Public License along with
1.19 - * JITCraft. If not, see http://www.gnu.org/licenses/.
1.20 - */
1.21 -#include "Zone.h"
1.22 -#include "StringPool.h"
1.23 -#include "Strings.h"
1.24 -#include "Spaces.h"
1.25 -#include "Spaces-inl.h"
1.26 -#include "Heap-inl.h"
1.27 -
1.28 -using namespace ke;
1.29 -
1.30 -StringPool::StringPool(Zone *zone)
1.31 - : zone_(zone),
1.32 - set_(ZoneAllocatorPolicy())
1.33 -{
1.34 -}
1.35 -
1.36 -StringPool::~StringPool()
1.37 -{
1.38 -}
1.39 -
1.40 -bool
1.41 -StringPool::initialize()
1.42 -{
1.43 - if (!set_.init(32))
1.44 - return false;
1.45 - return true;
1.46 -}
1.47 -
1.48 -String *
1.49 -StringPool::add(const char *str, size_t length)
1.50 -{
1.51 - StringSet::Insert i = set_.findForAdd(CharsAndLength(str, length));
1.52 - if (i.found())
1.53 - return *i;
1.54 -
1.55 - Local<String> obj(zone_, String::New(zone_, str, length, Heap::Tenure_Old));
1.56 - if (!obj)
1.57 - return NULL;
1.58 -
1.59 - set_.add(i, obj);
1.60 - return obj;
1.61 -}
1.62 -
1.63 -void
1.64 -StringPool::sweep()
1.65 -{
1.66 - for (StringSet::iterator i(&set_); !i.empty(); i.next()) {
1.67 - String *obj = *i;
1.68 - MarkBit bits = HeapChunk::GetMarkBit(obj);
1.69 - if (HeapChunk::IsWhite(bits))
1.70 - i.erase();
1.71 - else
1.72 - assert(HeapChunk::IsBlack(bits));
1.73 - }
1.74 - set_.checkDensity();
1.75 -}
1.76 +/*
1.77 + * Copyright (C) 2012 David Anderson
1.78 + *
1.79 + * This file is part of JITCraft.
1.80 + *
1.81 + * JITCraft is free software: you can redistribute it and/or modify it under
1.82 + * the terms of the GNU General Public License as published by the Free
1.83 + * Software Foundation, either version 3 of the License, or (at your option)
1.84 + * any later version.
1.85 + *
1.86 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.87 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.88 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.89 + *
1.90 + * You should have received a copy of the GNU General Public License along with
1.91 + * JITCraft. If not, see http://www.gnu.org/licenses/.
1.92 + */
1.93 +#include "Zone.h"
1.94 +#include "StringPool.h"
1.95 +#include "Strings.h"
1.96 +#include "Spaces.h"
1.97 +#include "Spaces-inl.h"
1.98 +#include "Heap-inl.h"
1.99 +
1.100 +using namespace ke;
1.101 +
1.102 +StringPool::StringPool(Zone *zone)
1.103 + : zone_(zone),
1.104 + set_(ZoneAllocatorPolicy())
1.105 +{
1.106 +}
1.107 +
1.108 +StringPool::~StringPool()
1.109 +{
1.110 +}
1.111 +
1.112 +bool
1.113 +StringPool::initialize()
1.114 +{
1.115 + if (!set_.init(32))
1.116 + return false;
1.117 + return true;
1.118 +}
1.119 +
1.120 +String *
1.121 +StringPool::add(const char *str, size_t length)
1.122 +{
1.123 + StringSet::Insert i = set_.findForAdd(CharsAndLength(str, length));
1.124 + if (i.found())
1.125 + return *i;
1.126 +
1.127 + Local<String> obj(zone_, String::New(zone_, str, length, Heap::Tenure_Old));
1.128 + if (!obj)
1.129 + return NULL;
1.130 +
1.131 + set_.add(i, obj);
1.132 + return obj;
1.133 +}
1.134 +
1.135 +void
1.136 +StringPool::sweep()
1.137 +{
1.138 + for (StringSet::iterator i(&set_); !i.empty(); i.next()) {
1.139 + String *obj = *i;
1.140 + MarkBit bits = HeapChunk::GetMarkBit(obj);
1.141 + if (HeapChunk::IsWhite(bits))
1.142 + i.erase();
1.143 + else
1.144 + assert(HeapChunk::IsBlack(bits));
1.145 + }
1.146 + set_.checkDensity();
1.147 +}