Jump to content

about the banword


Recommended Posts

Open the banword.cpp 

Search it

CBanwordManager::~CBanwordManager()
{
}

Change it

CBanwordManager::~CBanwordManager()
{
	delete [] m_hashmap_words;
}

Search it

bool CBanwordManager::Initialize(TBanwordTable * p, WORD wSize)

Remove this

	m_hashmap_words.clear();

Looks like

bool CBanwordManager::Initialize(TBanwordTable * p, WORD wSize)
{
	for (WORD i = 0; i < wSize; ++i, ++p)
		m_hashmap_words[p->szWord] = true;

	char szBuf[256];
	snprintf(szBuf, sizeof(szBuf), "Banword reloaded! (total %zu banwords)", m_hashmap_words.size());
	SendLog(szBuf);
	return true;
}

Search it

char szBuf[256];

Change it

char szBuf[QUERY_MAX_LEN];

Search it

bool CBanwordManager::Initialize(TBanwordTable * p, WORD wSize)

Change it

bool CBanwordManager::Initialize(TBanwordTable * p, UINT wSize)

Search it

for (WORD i = 0; i < wSize; ++i, ++p)

Change it

for (UINT i = 0; i < wSize; ++i, ++p)

Search it

snprintf(szBuf, sizeof(szBuf), "Banword reloaded! (total %zu banwords)", m_hashmap_words.size());

Change it

snprintf(szBuf, sizeof(szBuf), "Banword reloaded! (total %u banwords)", m_hashmap_words.size());

Search it

bool CBanwordManager::CheckString(const char * c_pszString, size_t _len)
{
	if (m_hashmap_words.empty())
		return false;

	typeof(m_hashmap_words.begin()) it = m_hashmap_words.begin();

	while (it != m_hashmap_words.end())
	{
		const std::string & r = it->first;
		const char * tmp = c_pszString;
		ssize_t len = _len;

		while (len > 0)
		{
			if (is_twobyte(tmp))
			{
				if (!strncmp(tmp, r.c_str(), r.size()))
					return true;

				tmp += 2;
				len -= 2;
			}
			else
			{
				if (!strncmp(tmp, r.c_str(), r.size()))
					return true;

				++tmp;
				--len;
			}
		}

		it++;
	}

	return false;
}

Change it

bool CBanwordManager::CheckString(const char *c_pszString, size_t _len) {
    if (m_hashmap_words.empty()) {
        return false;
    }

    for (auto it = m_hashmap_words.cbegin(); it != m_hashmap_words.cend(); ++it) {
        const std::string &r = it->first;
        const char *tmp = c_pszString;
        ssize_t len = _len;

        while (len > 0) {
            if (!strncmp(tmp, r.c_str(), r.size())) {
                return true;
            }

            if (is_twobyte(tmp)) {
                tmp += 2;
                len -= 2;
            } else {
                ++tmp;
                --len;
            }
        }
    }

    return false;
}

open banword.h and search it

bool Initialize(TBanwordTable * p, WORD wSize);

Change it

bool Initialize(TBanwordTable * p, UINT wSize);

That is now completely finish.

  • Good 1
Link to comment
Share on other sites

  • 3 weeks later...
  • Contributor

So you basically changed nothing by changing a lot.

 

Why did you remove m_hashmap_words.clear() from CBanwordManager::Initialize() ? What's going to happen when you reload the banword? Also, why did you increase the buffer from 256 bytes to 65k if you'll only use like.. 100 characters tops?

The only good thing I see changed here is the removal of double "if (!strncmp(tmp, r.c_str(), r.size())) return true;" which makes the code shorter by 2 lines(doesn't affect runtime perf).

 

Also, I'm curious about what compiler allows you to delete[] an std::unordered_map<>, which is what SCOOB pointed out earlier.

Edited by Amun
  • kekw 1
  • Good 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.