Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge branch 'i92'
Browse files Browse the repository at this point in the history
* 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
kana committed Dec 11, 2010
2 parents 61a8bd5 + 4cc2a29 commit b84a663
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
43 changes: 37 additions & 6 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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) {
Expand All @@ -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(' ');
Expand Down Expand Up @@ -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');
},
Expand Down
2 changes: 1 addition & 1 deletion prafbe
Submodule prafbe updated 2 files
+1 −0 prafbe.js
+24 −0 spec/core.js
1 change: 1 addition & 0 deletions spec/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit b84a663

Please sign in to comment.