faml 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +6 -6
- data/ext/attribute_builder/attribute_builder.cc +23 -24
- data/ext/attribute_builder/extconf.rb +1 -1
- data/incompatibilities/README.md +2 -2
- data/lib/faml/stats.rb +5 -5
- data/lib/faml/version.rb +1 -1
- data/spec/compiler_newline_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c14024dd27014d4d1b41a1313b1e85f2ba2d4be2
|
4
|
+
data.tar.gz: 1125ce25dca9c6daafe7fc42d04be96057ad9ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b39519a1514a4eb09800291310e7be514a70f8d51ec1eff80f048baafa7fe8237b93ae2cba8ff4ea400a1a0559a89ad4574bd3e12e031684ac34579095982e6
|
7
|
+
data.tar.gz: 2f0f94f8ee613989a4476d0d7165e1712259be33cb679834f1f2eb9a625c384bd26dc49fdb1ec2c713519531d4107a2b8d5dd70d8227264c20463c72c9a108d5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.7.2 (2015-12-13)
|
2
|
+
- Improve AttributeBuilder performance
|
3
|
+
- Replace std::ostringstream with std::string
|
4
|
+
- Fix compile error in some platforms
|
5
|
+
|
1
6
|
## 0.7.1 (2015-12-04)
|
2
7
|
- Fix compiler options for old compilers
|
3
8
|
|
@@ -18,7 +23,7 @@
|
|
18
23
|
- https://github.com/eagletmt/faml/pull/41
|
19
24
|
|
20
25
|
## 0.6.3 (2015-11-22)
|
21
|
-
- Remove duplicated class in
|
26
|
+
- Remove duplicated class in runtime attribute case
|
22
27
|
- `%span.foo{h}` where `h = { class: 'foo bar' }` now renders `<span class='bar foo'></span>` .
|
23
28
|
- `%span.foo{class: 'foo bar'}` renders `<span class='bar foo'></span>` since v0.2.12 .
|
24
29
|
|
data/README.md
CHANGED
@@ -90,7 +90,7 @@ You have to set `Faml::Engine.options[:extend_helpers] = true` to use `preserve`
|
|
90
90
|
### Others
|
91
91
|
If you find other incompatibility, please report it to me :-p.
|
92
92
|
|
93
|
-
## Why faml
|
93
|
+
## Why is faml faster?
|
94
94
|
### Temple backend
|
95
95
|
I use [temple](https://github.com/judofyr/temple) to achieve faster template rendering.
|
96
96
|
It's used by [slim](https://github.com/slim-template/slim) template language & engine which is known as fast.
|
@@ -120,18 +120,18 @@ The runtime hash merging is implemented by C extension in faml.
|
|
120
120
|
Internally, attributes are categolized into three types.
|
121
121
|
|
122
122
|
1. Static attributes
|
123
|
-
- Both the key and the value are
|
123
|
+
- Both the key and the value are static.
|
124
124
|
- Compiled into string literals.
|
125
125
|
- Fastest.
|
126
126
|
- e.g. `%input{checked: false}`
|
127
127
|
2. Dynamic attributes
|
128
|
-
- The key is
|
128
|
+
- The key is static but the value isn't.
|
129
129
|
- The key is compiled into string literal. The value is interpolated at run-time.
|
130
130
|
- Relatively fast.
|
131
131
|
- e.g. `%input{checked: helper_method(@record)}`
|
132
|
-
3.
|
133
|
-
- Both the key and the value are non-
|
134
|
-
- The attributes are stringified at
|
132
|
+
3. Runtime attributes
|
133
|
+
- Both the key and the value are non-static expression.
|
134
|
+
- The attributes are stringified at runtime.
|
135
135
|
- Slow.
|
136
136
|
- e.g. `%input{helper_method(@record)}`
|
137
137
|
|
@@ -3,7 +3,6 @@
|
|
3
3
|
#include "houdini.h"
|
4
4
|
#include <algorithm>
|
5
5
|
#include <map>
|
6
|
-
#include <sstream>
|
7
6
|
#include <string>
|
8
7
|
#include <vector>
|
9
8
|
|
@@ -194,20 +193,20 @@ static void join_class_attribute(attribute_holder& attributes) {
|
|
194
193
|
|
195
194
|
std::sort(ary.begin(), ary.end());
|
196
195
|
ary.erase(std::unique(ary.begin(), ary.end()), ary.end());
|
197
|
-
std::
|
196
|
+
std::string buf;
|
198
197
|
for (std::vector<std::string>::const_iterator it = ary.begin();
|
199
198
|
it != ary.end(); ++it) {
|
200
199
|
if (it != ary.begin()) {
|
201
|
-
|
200
|
+
buf.push_back(' ');
|
202
201
|
}
|
203
|
-
|
202
|
+
buf.append(*it);
|
204
203
|
}
|
205
|
-
attributes.upsert("class", attribute_value(
|
204
|
+
attributes.upsert("class", attribute_value(buf));
|
206
205
|
}
|
207
206
|
|
208
207
|
static void join_id_attribute(attribute_holder& attributes) {
|
209
208
|
const std::vector<attribute_value>& ids = attributes.ids_;
|
210
|
-
std::
|
209
|
+
std::string buf;
|
211
210
|
bool first = true;
|
212
211
|
|
213
212
|
for (std::vector<attribute_value>::const_iterator it = ids.begin();
|
@@ -217,16 +216,16 @@ static void join_id_attribute(attribute_holder& attributes) {
|
|
217
216
|
break;
|
218
217
|
case ATTRIBUTE_TYPE_TRUE:
|
219
218
|
if (!first) {
|
220
|
-
|
219
|
+
buf.push_back('_');
|
221
220
|
}
|
222
|
-
|
221
|
+
buf.append("true");
|
223
222
|
first = false;
|
224
223
|
break;
|
225
224
|
case ATTRIBUTE_TYPE_VALUE:
|
226
225
|
if (!first) {
|
227
|
-
|
226
|
+
buf.push_back('_');
|
228
227
|
}
|
229
|
-
|
228
|
+
buf.append(it->str_);
|
230
229
|
first = false;
|
231
230
|
break;
|
232
231
|
}
|
@@ -235,7 +234,7 @@ static void join_id_attribute(attribute_holder& attributes) {
|
|
235
234
|
return;
|
236
235
|
}
|
237
236
|
|
238
|
-
attributes.upsert("id", attribute_value(
|
237
|
+
attributes.upsert("id", attribute_value(buf));
|
239
238
|
}
|
240
239
|
|
241
240
|
static void delete_falsey_values(attributes_type& m) {
|
@@ -268,34 +267,35 @@ static attributes_type merge(VALUE object_ref, int argc, VALUE* argv) {
|
|
268
267
|
return attributes.m_;
|
269
268
|
}
|
270
269
|
|
271
|
-
static void put_attribute(std::
|
270
|
+
static void put_attribute(std::string& buf,
|
272
271
|
const std::string& attr_quote, const std::string& key,
|
273
272
|
const std::string& value) {
|
274
|
-
|
273
|
+
buf.append(" ").append(key).append("=").append(attr_quote);
|
275
274
|
|
276
275
|
gh_buf ob = GH_BUF_INIT;
|
277
276
|
if (houdini_escape_html0(&ob, (const uint8_t*)value.data(), value.size(),
|
278
277
|
0)) {
|
279
|
-
|
278
|
+
buf.append(std::string(ob.ptr, ob.size));
|
280
279
|
gh_buf_free(&ob);
|
281
280
|
} else {
|
282
|
-
|
281
|
+
buf.append(value);
|
283
282
|
}
|
284
|
-
|
283
|
+
buf.append(attr_quote);
|
285
284
|
}
|
286
285
|
|
287
|
-
static void build_attribute(std::
|
286
|
+
static void build_attribute(std::string& buf,
|
288
287
|
const std::string& attr_quote, int is_html,
|
289
288
|
const std::string& key,
|
290
289
|
const attribute_value& value) {
|
291
290
|
if (value.type_ == ATTRIBUTE_TYPE_TRUE) {
|
292
291
|
if (is_html) {
|
293
|
-
|
292
|
+
buf.push_back(' ');
|
293
|
+
buf.append(key);
|
294
294
|
} else {
|
295
|
-
put_attribute(
|
295
|
+
put_attribute(buf, attr_quote, key, key);
|
296
296
|
}
|
297
297
|
} else {
|
298
|
-
put_attribute(
|
298
|
+
put_attribute(buf, attr_quote, key, value.str_);
|
299
299
|
}
|
300
300
|
}
|
301
301
|
|
@@ -310,14 +310,13 @@ static VALUE m_build(int argc, VALUE* argv, RB_UNUSED_VAR(VALUE self)) {
|
|
310
310
|
object_ref = argv[2];
|
311
311
|
const attributes_type attributes = merge(object_ref, argc - 3, argv + 3);
|
312
312
|
|
313
|
-
std::
|
313
|
+
std::string buf;
|
314
314
|
for (attributes_type::const_iterator it = attributes.begin();
|
315
315
|
it != attributes.end(); ++it) {
|
316
|
-
build_attribute(
|
316
|
+
build_attribute(buf, attr_quote, is_html, it->first, it->second);
|
317
317
|
}
|
318
318
|
|
319
|
-
|
320
|
-
return rb_utf8_str_new(str.data(), str.size());
|
319
|
+
return rb_utf8_str_new(buf.data(), buf.size());
|
321
320
|
}
|
322
321
|
|
323
322
|
static VALUE m_normalize_data(RB_UNUSED_VAR(VALUE self), VALUE data) {
|
data/incompatibilities/README.md
CHANGED
data/lib/faml/stats.rb
CHANGED
@@ -13,7 +13,7 @@ module Faml
|
|
13
13
|
:dynamic_attribute_count,
|
14
14
|
:dynamic_attribute_with_data_count,
|
15
15
|
:dynamic_attribute_with_newline_count,
|
16
|
-
:
|
16
|
+
:runtime_attribute_count,
|
17
17
|
:object_reference_count,
|
18
18
|
:multi_attribute_count,
|
19
19
|
:ast_types
|
@@ -133,7 +133,7 @@ module Faml
|
|
133
133
|
if call_ast.type == :send && call_ast.children[0].nil? && call_ast.children[1] == :call && !call_ast.children[3].nil?
|
134
134
|
info.multi_attribute_count += 1
|
135
135
|
else
|
136
|
-
info.
|
136
|
+
info.runtime_attribute_count += 1
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
@@ -142,8 +142,8 @@ module Faml
|
|
142
142
|
def report_attribute_stats(info)
|
143
143
|
static = info.static_attribute_count
|
144
144
|
dynamic = info.dynamic_attribute_count + info.dynamic_attribute_with_data_count + info.dynamic_attribute_with_newline_count
|
145
|
-
|
146
|
-
total = static + dynamic +
|
145
|
+
runtime = info.runtime_attribute_count + info.multi_attribute_count + info.object_reference_count
|
146
|
+
total = static + dynamic + runtime
|
147
147
|
puts 'Attribute stats'
|
148
148
|
printf(" Empty attributes: %d\n", info.empty_attribute_count)
|
149
149
|
printf(" Attributes with id or class only: %d\n", info.static_id_or_class_attribute_count)
|
@@ -151,7 +151,7 @@ module Faml
|
|
151
151
|
printf(" Dynamic attributes: %d (%.2f%%)\n", dynamic, dynamic * 100.0 / total)
|
152
152
|
printf(" with data: %d\n", info.dynamic_attribute_with_data_count)
|
153
153
|
printf(" with newline: %d\n", info.dynamic_attribute_with_newline_count)
|
154
|
-
printf("
|
154
|
+
printf(" Runtime attributes: %d (%.2f%%)\n", runtime, runtime * 100.0 / total)
|
155
155
|
printf(" with multiple arguments: %d\n", info.multi_attribute_count)
|
156
156
|
printf(" with object reference: %d\n", info.object_reference_count)
|
157
157
|
end
|
data/lib/faml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -521,7 +521,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
521
521
|
version: '0'
|
522
522
|
requirements: []
|
523
523
|
rubyforge_project:
|
524
|
-
rubygems_version: 2.
|
524
|
+
rubygems_version: 2.5.0
|
525
525
|
signing_key:
|
526
526
|
specification_version: 4
|
527
527
|
summary: Faster implementation of Haml template language.
|