Commit 529331cc authored by yoav@yoav.ws's avatar yoav@yoav.ws

Convert MediaQueryTokenizer's codepoints array to be static data.

Since there's no reason that the MediaQueryTokenizer's codepoints array would be created dynamically, I've created it here as an initialized array.
I used the build scripts to do that.



BUG=

Review URL: https://codereview.chromium.org/209503003

git-svn-id: svn://svn.chromium.org/blink/trunk@170074 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 72c43426
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import in_generator
import sys
import os
module_basename = os.path.basename(__file__)
module_pyname = os.path.splitext(module_basename)[0] + '.py'
CPP_TEMPLATE = """
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Auto-generated by {module_pyname}
const MediaQueryTokenizer::CodePoint MediaQueryTokenizer::codePoints[{array_size}] = {{
{token_lines}
}};
const unsigned codePointsNumber = {array_size};
"""
def token_type(i):
codepoints = {'(': 'leftParenthesis',
')': 'rightParenthesis',
'+': 'plusOrFullStop',
'.': 'plusOrFullStop',
'-': 'hyphenMinus',
',': 'comma',
'/': 'solidus',
'\\': 'reverseSolidus',
':': 'colon',
';': 'semiColon',
}
whitespace = '\n\r\t\f '
c = chr(i)
if c in whitespace:
return 'whiteSpace'
if c.isdigit():
return 'asciiDigit'
if c.isalpha() or c == '_':
return 'nameStart'
if i == 0:
return 'endOfFile'
return codepoints.get(c)
class MakeMediaQueryTokenizerCodePointsWriter(in_generator.Writer):
defaults = {
'Conditional': None,
'RuntimeEnabled': None,
'ImplementedAs': None,
}
filters = {
}
default_parameters = {
'namespace': '',
'export': '',
}
def __init__(self, in_file_path):
super(MakeMediaQueryTokenizerCodePointsWriter, self).__init__(in_file_path)
self._outputs = {
('MediaQueryTokenizerCodepoints.cpp'): self.generate,
}
self._template_context = {
'namespace': '',
'export': '',
}
def generate(self):
array_size = 128 # SCHAR_MAX + 1
token_lines = [' &MediaQueryTokenizer::%s,' % token_type(i)
if token_type(i) else ' 0,'
for i in range(array_size)]
return CPP_TEMPLATE.format(array_size=array_size, token_lines='\n'.join(token_lines), module_pyname=module_pyname)
if __name__ == '__main__':
in_generator.Maker(MakeMediaQueryTokenizerCodePointsWriter).main(sys.argv)
......@@ -253,6 +253,22 @@
'--defines', '<(feature_defines)',
],
},
{
'action_name': 'MediaQueryTokenizerCodepoints',
'inputs': [
'../build/scripts/make_mediaquery_tokenizer_codepoints.py',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/blink/MediaQueryTokenizerCodepoints.cpp',
],
'action': [
'python',
'../build/scripts/make_mediaquery_tokenizer_codepoints.py',
'--output_dir',
'<(SHARED_INTERMEDIATE_DIR)/blink',
'--defines', '<(feature_defines)',
],
},
{
'action_name': 'StylePropertyShorthand',
'inputs': [
......
......@@ -5,54 +5,16 @@
#include "config.h"
#include "core/css/parser/MediaQueryTokenizer.h"
namespace WebCore {
#include "MediaQueryTokenizerCodepoints.cpp"
}
#include "core/css/parser/MediaQueryInputStream.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "wtf/unicode/CharacterNames.h"
namespace WebCore {
const unsigned codePointsNumber = SCHAR_MAX + 1;
class MediaQueryTokenizer::CodePoints {
public:
MediaQueryTokenizer::CodePoint codePoints[codePointsNumber];
// FIXME: Move the codePoint array to be a static one, generated by build scripts
CodePoints()
{
memset(codePoints, 0, codePointsNumber);
codePoints['\n'] = &MediaQueryTokenizer::whiteSpace;
codePoints['\r'] = &MediaQueryTokenizer::whiteSpace;
codePoints['\t'] = &MediaQueryTokenizer::whiteSpace;
codePoints[' '] = &MediaQueryTokenizer::whiteSpace;
codePoints['\f'] = &MediaQueryTokenizer::whiteSpace;
codePoints['('] = &MediaQueryTokenizer::leftParenthesis;
codePoints[')'] = &MediaQueryTokenizer::rightParenthesis;
codePoints['+'] = &MediaQueryTokenizer::plusOrFullStop;
codePoints['.'] = &MediaQueryTokenizer::plusOrFullStop;
codePoints[','] = &MediaQueryTokenizer::comma;
codePoints['-'] = &MediaQueryTokenizer::hyphenMinus;
codePoints['/'] = &MediaQueryTokenizer::solidus;
codePoints[':'] = &MediaQueryTokenizer::colon;
codePoints[';'] = &MediaQueryTokenizer::semiColon;
codePoints['\\'] = &MediaQueryTokenizer::reverseSolidus;
for (unsigned char digit = '0'; digit <= '9'; ++digit)
codePoints[digit] = &MediaQueryTokenizer::asciiDigit;
for (unsigned char alpha = 'a'; alpha <= 'z'; ++alpha)
codePoints[alpha] = &MediaQueryTokenizer::nameStart;
for (unsigned char alpha = 'A'; alpha <= 'Z'; ++alpha)
codePoints[alpha] = &MediaQueryTokenizer::nameStart;
codePoints['_'] = &MediaQueryTokenizer::nameStart;
codePoints[kEndOfFileMarker] = &MediaQueryTokenizer::endOfFile;
}
};
MediaQueryTokenizer::CodePoints* MediaQueryTokenizer::codePoints()
{
static CodePoints codePoints;
return &codePoints;
}
// http://dev.w3.org/csswg/css-syntax/#name-start-code-point
static bool isNameStart(UChar c)
{
......@@ -216,7 +178,7 @@ MediaQueryToken MediaQueryTokenizer::nextToken()
if (isASCII(cc)) {
ASSERT_WITH_SECURITY_IMPLICATION(cc < codePointsNumber);
codePointFunc = codePoints()->codePoints[cc];
codePointFunc = codePoints[cc];
} else {
codePointFunc = &MediaQueryTokenizer::nameStart;
}
......
......@@ -20,10 +20,7 @@ class MediaQueryTokenizer {
WTF_MAKE_FAST_ALLOCATED;
public:
static void tokenize(String, Vector<MediaQueryToken>&);
private:
class CodePoints;
MediaQueryTokenizer(MediaQueryInputStream&);
MediaQueryToken nextToken();
......@@ -48,6 +45,8 @@ private:
typedef MediaQueryToken (MediaQueryTokenizer::*CodePoint)(UChar);
static const CodePoint codePoints[];
MediaQueryToken whiteSpace(UChar);
MediaQueryToken leftParenthesis(UChar);
MediaQueryToken rightParenthesis(UChar);
......@@ -62,8 +61,6 @@ private:
MediaQueryToken nameStart(UChar);
MediaQueryToken endOfFile(UChar);
CodePoints* codePoints();
MediaQueryInputStream& m_input;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment