<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>stardict &#8211; 天地一沙鸥</title>
	<atom:link href="https://haoluobo.com/tag/stardict/feed/" rel="self" type="application/rss+xml" />
	<link>https://haoluobo.com</link>
	<description>to be continue....</description>
	<lastBuildDate>Thu, 01 Jan 2009 16:03:04 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>提升pystardict对stardict字典文件的加载速度</title>
		<link>https://haoluobo.com/2009/01/%e6%8f%90%e5%8d%87pystardict%e5%af%b9stardict%e5%ad%97%e5%85%b8%e6%96%87%e4%bb%b6%e7%9a%84%e5%8a%a0%e8%bd%bd%e9%80%9f%e5%ba%a6/</link>
					<comments>https://haoluobo.com/2009/01/%e6%8f%90%e5%8d%87pystardict%e5%af%b9stardict%e5%ad%97%e5%85%b8%e6%96%87%e4%bb%b6%e7%9a%84%e5%8a%a0%e8%bd%bd%e9%80%9f%e5%ba%a6/#comments</comments>
		
		<dc:creator><![CDATA[vicalloy]]></dc:creator>
		<pubDate>Thu, 01 Jan 2009 16:03:04 +0000</pubDate>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[pystardict]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[stardict]]></category>
		<guid isPermaLink="false">/index.php/2009/01/%e6%8f%90%e5%8d%87pystardict%e5%af%b9stardict%e5%ad%97%e5%85%b8%e6%96%87%e4%bb%b6%e7%9a%84%e5%8a%a0%e8%bd%bd%e9%80%9f%e5%ba%a6/</guid>

					<description><![CDATA[stardict是linux下使用最广的字段程序，在广大网友的贡献下，stardict的字典文件可是相当的丰富 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a href="http://stardict.sourceforge.net/">stardict</a>是linux下使用最广的字段程序，在广大网友的贡献下，stardict的字典文件可是相当的丰富。<a href="http://github.com/lig/pystardict/tree/master">pystardict</a>是一个读取startdict字典文件的python库。<br />
前些天在邮件列表看到有人提到用<a href="http://github.com/lig/pystardict/tree/master">pystardict</a>加载stardict的字典文件速度慢的问题。加载字段文件时需要解析字段的索引文件（.idx）取出所有的单词信息。但python未提供指针，处理速度远比不上c。<br />
我尝试用正则表达式对索引解析部分的代码进行重写，经测试，速度应当能提高3/5的样子。感觉依旧不是太理想，不知道是否还有什么别的办法。<br />
我将改动后的代码生成了一个patch发给pystardict的作者，不知道是否会被采用。<br />
下面是idx解析的关键代码（idx的结构确实是非常的简单）：</p>
<pre lang="python" line="1">        import re
        rawstr = r"""([\d\D]+?\x00[\d\D]{8})"""
        matchstr = self._file
        match_obj = re.findall(rawstr, matchstr)
        for e in match_obj:
            c = e.find('\x00')
            record_tuple = unpack('!%sc1x%sL' % (c, idx_offset_format), e)
            word, cords = ''.join(record_tuple[:c]), record_tuple[c:]
            self._idx[word] = cords</pre>
<p>附件：<a href="/wp-content/uploads/2009/01/pystardict.zip">提高了字典加载速度的pystardict</a></p>
<h3>后记</h3>
<p>今天收到原作者的邮件，我提交的patch已经接收了，新的pystardict已经更新过。不过他用的是我早些提交的patch。那个patch里，我unpack的时候没有做跳过\x00的处理，所以要稍微丑点。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://haoluobo.com/2009/01/%e6%8f%90%e5%8d%87pystardict%e5%af%b9stardict%e5%ad%97%e5%85%b8%e6%96%87%e4%bb%b6%e7%9a%84%e5%8a%a0%e8%bd%bd%e9%80%9f%e5%ba%a6/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
