Permalink
Browse files

Merge branch 'i92'

* i92:
  Add preference maximum_size_of_prafbe_dict_kib
  Compact prafbe dicts if necessary
  englishize: Refactor - Remove an extra comment
  englishize: Support "kib" suffix
  prafbe: Update for bugfix on compact
  • Loading branch information...
2 parents 61a8bd5 + 4cc2a29 commit b84a663f9dc862fdfed4bb4fdb5b9e2e9c4dd1e4 @kana committed Dec 11, 2010
Showing with 39 additions and 7 deletions.
  1. +37 −6 core.js
  2. +1 −1 prafbe
  3. +1 −0 spec/misc.js
View
43 core.js
@@ -1392,8 +1392,35 @@ function is_spam_tweet_p(tweet) //{{{2
function save_prafbe_learning_result() //{{{2
{
- g_preferences.prafbe_right_dict.save();
- g_preferences.prafbe_wrong_dict.save();
+ var MAXIMUM_BYTES = g_preferences.maximum_size_of_prafbe_dict_kib() * 1024;
+ var kibibytes = function (bytes) {
+ return Math.round(bytes / 1024);
+ };
+ var save = function (p) {
+ var original_size = p.encode(p()).length;
+ var l = original_size;
+ while (MAXIMUM_BYTES < l) {
+ prafbe.compact(p());
+ l = p.encode(p()).length;
+ }
+ p.save();
+
+ if (l != original_size) {
+ log_notice(
+ p.id,
+ [
+ 'Compacted:',
+ kibibytes(original_size),
+ 'KiB =>',
+ kibibytes(l),
+ 'KiB'
+ ].join(' ')
+ );
+ }
+ };
+
+ save(g_preferences.prafbe_right_dict);
+ save(g_preferences.prafbe_wrong_dict);
}
@@ -1981,10 +2008,6 @@ function compare_tweet_ids(l, r) //{{{2
function englishize(id) //{{{2
{
- // 'foo_bar_baz' ==> 'Foo bar baz'
- // 'foo_bar_sec' ==> 'Foo bar (sec.)'
- // 'foo_uri' ==> 'Foo URI'
-
var words = id.split('_');
if (1 <= words.length) {
@@ -1996,6 +2019,8 @@ function englishize(id) //{{{2
var i = words.length - 1;
if (words[i] == 'sec')
words[i] = '(sec.)';
+ if (words[i] == 'kib')
+ words[i] = '(KiB)';
}
return words.join(' ');
@@ -2546,6 +2571,12 @@ $(document).ready(function () { //{{{2
rows: 3,
}
); //}}}
+ g_preferences.register('maximum_size_of_prafbe_dict_kib', //{{{
+ 1024,
+ {
+ is_advanced_p: true,
+ }
+ ); //}}}
g_preferences.apply('initialization');
},
2 prafbe
Submodule prafbe updated from ade35c to c4e567
View
@@ -54,6 +54,7 @@ describe('Misc.', function () {
expect(englishize('foo_bar_baz')).toEqual('Foo bar baz');
expect(englishize('foo_bar_sec')).toEqual('Foo bar (sec.)');
expect(englishize('foo_uri')).toEqual('Foo URI');
+ expect(englishize('foo_kib')).toEqual('Foo (KiB)');
});
});
describe('expand_template', function () {

0 comments on commit b84a663

Please sign in to comment.